Changeset 93306058 in rtems


Ignore:
Timestamp:
May 27, 2016, 12:43:19 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
af746b0
Parents:
0e1d11f3
git-author:
Sebastian Huber <sebastian.huber@…> (05/27/16 12:43:19)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/30/16 14:16:21)
Message:

score: _CORE_mutex_Check_dispatch_for_seize()

Move the safety check performed by
_CORE_mutex_Check_dispatch_for_seize() out of the performance critical
path and generalize it. Blocking on a thread queue with an unexpected
thread dispatch disabled level is illegal in all system states.

Add the expected thread dispatch disable level (which may be 1 or 2
depending on the operation) to Thread_queue_Context and use it in
_Thread_queue_Enqueue_critical().

Files:
32 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/psignalimpl.h

    r0e1d11f3 r93306058  
    7474 */
    7575
    76 #define _POSIX_signals_Acquire( lock_context ) \
    77   _Thread_queue_Acquire( &_POSIX_signals_Wait_queue, lock_context )
     76RTEMS_INLINE_ROUTINE void _POSIX_signals_Acquire(
     77  Thread_queue_Context *queue_context
     78)
     79{
     80  _Thread_queue_Acquire(
     81    &_POSIX_signals_Wait_queue,
     82    &queue_context->Lock_context
     83  );
     84}
    7885
    79 #define _POSIX_signals_Release( lock_context ) \
    80   _Thread_queue_Release( &_POSIX_signals_Wait_queue, lock_context )
     86RTEMS_INLINE_ROUTINE void _POSIX_signals_Release(
     87  Thread_queue_Context *queue_context
     88)
     89{
     90  _Thread_queue_Release(
     91    &_POSIX_signals_Wait_queue,
     92    &queue_context->Lock_context
     93  );
     94}
    8195
    8296/**
  • cpukit/posix/src/condwaitsupp.c

    r0e1d11f3 r93306058  
    8787
    8888  if ( !already_timedout ) {
     89    _Thread_queue_Context_set_expected_level( &queue_context, 2 );
    8990    _Thread_queue_Enqueue_critical(
    9091      &the_cond->Wait_queue.Queue,
     
    9394      STATES_WAITING_FOR_CONDITION_VARIABLE,
    9495      timeout,
    95       &queue_context.Lock_context
     96      &queue_context
    9697    );
    9798  } else {
  • cpukit/posix/src/killinfo.c

    r0e1d11f3 r93306058  
    7676  POSIX_signals_Siginfo_node  *psiginfo;
    7777  Thread_queue_Heads          *heads;
    78   ISR_lock_Context             lock_context;
     78  Thread_queue_Context         queue_context;
    7979  Per_CPU_Control             *cpu_self;
    8080
     
    335335  _POSIX_signals_Set_process_signals( mask );
    336336
    337   _POSIX_signals_Acquire( &lock_context );
     337  _Thread_queue_Context_initialize( &queue_context );
     338  _POSIX_signals_Acquire( &queue_context );
    338339
    339340  if ( _POSIX_signals_Vectors[ sig ].sa_flags == SA_SIGINFO ) {
     
    342343      _Chain_Get_unprotected( &_POSIX_signals_Inactive_siginfo );
    343344    if ( !psiginfo ) {
    344       _POSIX_signals_Release( &lock_context );
     345      _POSIX_signals_Release( &queue_context );
    345346      _Thread_Dispatch_enable( cpu_self );
    346347      rtems_set_errno_and_return_minus_one( EAGAIN );
     
    355356  }
    356357
    357   _POSIX_signals_Release( &lock_context );
     358  _POSIX_signals_Release( &queue_context );
    358359  DEBUG_STEP("\n");
    359360  _Thread_Dispatch_enable( cpu_self );
  • cpukit/posix/src/nanosleep.c

    r0e1d11f3 r93306058  
    9393    executing,
    9494    STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL,
    95     ticks
     95    ticks,
     96    1
    9697  );
    9798
  • cpukit/posix/src/psignalclearsignals.c

    r0e1d11f3 r93306058  
    4848  sigset_t                    mask;
    4949  sigset_t                    signals_unblocked;
    50   ISR_lock_Context            lock_context;
     50  Thread_queue_Context        queue_context;
    5151  bool                        do_callout;
    5252  POSIX_signals_Siginfo_node *psiginfo;
     
    6969
    7070  if ( do_signals_acquire_release ) {
    71     _POSIX_signals_Acquire( &lock_context );
     71    _Thread_queue_Context_initialize( &queue_context );
     72    _POSIX_signals_Acquire( &queue_context );
    7273  }
    7374
     
    103104
    104105  if ( do_signals_acquire_release ) {
    105     _POSIX_signals_Release( &lock_context );
     106    _POSIX_signals_Release( &queue_context );
    106107  }
    107108
  • cpukit/posix/src/psignalsetprocesssignals.c

    r0e1d11f3 r93306058  
    3737)
    3838{
    39   ISR_lock_Context lock_context;
     39  Thread_queue_Context queue_context;
    4040
    41   _POSIX_signals_Acquire( &lock_context );
     41  _Thread_queue_Context_initialize( &queue_context );
     42  _POSIX_signals_Acquire( &queue_context );
    4243    _POSIX_signals_Pending |= mask;
    43   _POSIX_signals_Release( &lock_context );
     44  _POSIX_signals_Release( &queue_context );
    4445}
  • cpukit/posix/src/psignalunblockthread.c

    r0e1d11f3 r93306058  
    9797)
    9898{
    99   POSIX_API_Control  *api;
    100   int                 signo;
    101   uint32_t            hold_errno;
     99  POSIX_API_Control *api;
     100  int                signo;
     101  uint32_t           hold_errno;
    102102
    103103  (void) action;
     
    136136   */
    137137  while (1) {
    138     _POSIX_signals_Acquire( lock_context );
     138    Thread_queue_Context queue_context;
     139
     140    _Thread_queue_Context_initialize( &queue_context );
     141    _POSIX_signals_Acquire( &queue_context );
    139142      if ( !(api->signals_unblocked &
    140143            (api->signals_pending | _POSIX_signals_Pending)) ) {
    141        _POSIX_signals_Release( lock_context );
     144       _POSIX_signals_Release( &queue_context );
    142145       break;
    143146     }
    144     _POSIX_signals_Release( lock_context );
     147    _POSIX_signals_Release( &queue_context );
    145148
    146149    for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
  • cpukit/posix/src/pthreadjoin.c

    r0e1d11f3 r93306058  
    3333static int _POSIX_Threads_Join( pthread_t thread, void **value_ptr )
    3434{
    35   Thread_Control    *the_thread;
    36   ISR_lock_Context   lock_context;
    37   Per_CPU_Control   *cpu_self;
    38   Thread_Control    *executing;
    39   void              *value;
     35  Thread_Control       *the_thread;
     36  Thread_queue_Context  queue_context;
     37  Per_CPU_Control      *cpu_self;
     38  Thread_Control       *executing;
     39  void                 *value;
    4040
    41   the_thread = _Thread_Get( thread, &lock_context );
     41  _Thread_queue_Context_initialize( &queue_context );
     42  _Thread_queue_Context_set_expected_level( &queue_context, 1 );
     43  the_thread = _Thread_Get( thread, &queue_context.Lock_context );
    4244
    4345  if ( the_thread == NULL ) {
     
    4951
    5052  if ( executing == the_thread ) {
    51     _ISR_lock_ISR_enable( &lock_context );
     53    _ISR_lock_ISR_enable( &queue_context.Lock_context );
    5254    return EDEADLK;
    5355  }
    5456
    55   _Thread_State_acquire_critical( the_thread, &lock_context );
     57  _Thread_State_acquire_critical( the_thread, &queue_context.Lock_context );
    5658
    5759  if ( !_Thread_Is_joinable( the_thread ) ) {
    58     _Thread_State_release( the_thread, &lock_context );
     60    _Thread_State_release( the_thread, &queue_context.Lock_context );
    5961    return EINVAL;
    6062  }
     
    6365    value = the_thread->Life.exit_value;
    6466    _Thread_Clear_state_locked( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT );
    65     _Thread_Dispatch_disable_with_CPU( cpu_self, &lock_context );
    66     _Thread_State_release( the_thread, &lock_context );
     67    _Thread_Dispatch_disable_with_CPU( cpu_self, &queue_context.Lock_context );
     68    _Thread_State_release( the_thread, &queue_context.Lock_context );
    6769    _Thread_Dispatch_enable( cpu_self );
    6870  } else {
     
    7173      STATES_INTERRUPTIBLE_BY_SIGNAL | STATES_WAITING_FOR_JOIN,
    7274      executing,
    73       &lock_context
     75      &queue_context
    7476    );
    7577
  • cpukit/posix/src/sigaction.c

    r0e1d11f3 r93306058  
    3434)
    3535{
    36   ISR_lock_Context lock_context;
     36  Thread_queue_Context queue_context;
    3737
    3838  if ( !sig )
     
    5252    rtems_set_errno_and_return_minus_one( EINVAL );
    5353
    54   _POSIX_signals_Acquire( &lock_context );
     54  _Thread_queue_Context_initialize( &queue_context );
     55  _POSIX_signals_Acquire( &queue_context );
    5556
    5657  if ( oact )
     
    7778  }
    7879
    79   _POSIX_signals_Release( &lock_context );
     80  _POSIX_signals_Release( &queue_context );
    8081
    8182  return 0;
  • cpukit/posix/src/sigtimedwait.c

    r0e1d11f3 r93306058  
    7070)
    7171{
    72   Thread_Control    *executing;
    73   POSIX_API_Control *api;
    74   Watchdog_Interval  interval;
    75   siginfo_t          signal_information;
    76   siginfo_t         *the_info;
    77   int                signo;
    78   ISR_lock_Context   lock_context;
    79   int                error;
     72  Thread_Control       *executing;
     73  POSIX_API_Control    *api;
     74  Watchdog_Interval     interval;
     75  siginfo_t             signal_information;
     76  siginfo_t            *the_info;
     77  int                   signo;
     78  Thread_queue_Context  queue_context;
     79  int                   error;
    8080
    8181  /*
     
    116116  /* API signals pending? */
    117117
    118   _POSIX_signals_Acquire( &lock_context );
     118  _Thread_queue_Context_initialize( &queue_context );
     119  _POSIX_signals_Acquire( &queue_context );
    119120  if ( *set & api->signals_pending ) {
    120121    /* XXX real info later */
     
    128129      false
    129130    );
    130     _POSIX_signals_Release( &lock_context );
     131    _POSIX_signals_Release( &queue_context );
    131132
    132133    the_info->si_code = SI_USER;
     
    140141    signo = _POSIX_signals_Get_lowest( _POSIX_signals_Pending );
    141142    _POSIX_signals_Clear_signals( api, signo, the_info, true, false, false );
    142     _POSIX_signals_Release( &lock_context );
     143    _POSIX_signals_Release( &queue_context );
    143144
    144145    the_info->si_signo = signo;
     
    152153  executing->Wait.option          = *set;
    153154  executing->Wait.return_argument = the_info;
     155  _Thread_queue_Context_set_expected_level( &queue_context, 1 );
    154156  _Thread_queue_Enqueue_critical(
    155157    &_POSIX_signals_Wait_queue.Queue,
     
    158160    STATES_WAITING_FOR_SIGNAL | STATES_INTERRUPTIBLE_BY_SIGNAL,
    159161    interval,
    160     &lock_context
     162    &queue_context
    161163  );
    162164
  • cpukit/rtems/src/regiongetsegment.c

    r0e1d11f3 r93306058  
    8787        executing,
    8888        STATES_WAITING_FOR_SEGMENT,
    89         timeout
     89        timeout,
     90        2
    9091      );
    9192
  • cpukit/sapi/src/interrtext.c

    r0e1d11f3 r93306058  
    4646  "INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY",
    4747  "OBSOLETE_INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL",
    48   "INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE",
     48  "INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_FROM_BAD_STATE",
    4949  "INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0",
    5050  "OBSOLETE_INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP",
  • cpukit/score/include/rtems/score/coremuteximpl.h

    r0e1d11f3 r93306058  
    2222#include <rtems/score/chainimpl.h>
    2323#include <rtems/score/status.h>
    24 #include <rtems/score/sysstate.h>
    2524#include <rtems/score/threadimpl.h>
    2625#include <rtems/score/threadqimpl.h>
     
    9695 */
    9796Status_Control _CORE_mutex_Seize_interrupt_blocking(
    98   CORE_mutex_Control  *the_mutex,
    99   Thread_Control      *executing,
    100   Watchdog_Interval    timeout,
    101   ISR_lock_Context    *lock_context
     97  CORE_mutex_Control   *the_mutex,
     98  Thread_Control       *executing,
     99  Watchdog_Interval     timeout,
     100  Thread_queue_Context *queue_context
    102101);
    103 
    104 /**
    105  *  @brief Verifies that a mutex blocking seize is performed safely.
    106  *
    107  *  This macro is to verify that a mutex blocking seize is
    108  *  performed from a safe system state.  For example, one
    109  *  cannot block inside an isr.
    110  *
    111  *  @retval this method returns true if dispatch is in an unsafe state.
    112  */
    113 #define _CORE_mutex_Check_dispatch_for_seize(_wait) \
    114   (!_Thread_Dispatch_is_enabled() \
    115     && (_wait) \
    116     && (_System_state_Get() >= SYSTEM_STATE_UP))
    117102
    118103/**
     
    302287  Status_Control status;
    303288
    304   if ( _CORE_mutex_Check_dispatch_for_seize( wait ) ) {
    305     _Terminate(
    306       INTERNAL_ERROR_CORE,
    307       false,
    308       INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE
    309     );
    310   }
    311 
    312289  _CORE_mutex_Acquire_critical( the_mutex, queue_context );
    313290
     
    331308    executing,
    332309    timeout,
    333     &queue_context->Lock_context
     310    queue_context
    334311  );
    335312}
  • cpukit/score/include/rtems/score/coresemimpl.h

    r0e1d11f3 r93306058  
    205205  }
    206206
     207  _Thread_queue_Context_set_expected_level( queue_context, 1 );
    207208  _Thread_queue_Enqueue_critical(
    208209    &the_semaphore->Wait_queue.Queue,
     
    211212    STATES_WAITING_FOR_SEMAPHORE,
    212213    timeout,
    213     &queue_context->Lock_context
     214    queue_context
    214215  );
    215216  return _Thread_Wait_get_status( executing );
  • cpukit/score/include/rtems/score/interr.h

    r0e1d11f3 r93306058  
    155155  INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY,
    156156  OBSOLETE_INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL,
    157   INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE,
     157  INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_FROM_BAD_STATE,
    158158  INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0,
    159159  OBSOLETE_INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP,
  • cpukit/score/include/rtems/score/threadimpl.h

    r0e1d11f3 r93306058  
    233233
    234234void _Thread_Join(
    235   Thread_Control    *the_thread,
    236   States_Control     waiting_for_join,
    237   Thread_Control    *executing,
    238   ISR_lock_Context  *lock_context
     235  Thread_Control       *the_thread,
     236  States_Control        waiting_for_join,
     237  Thread_Control       *executing,
     238  Thread_queue_Context *queue_context
    239239);
    240240
  • cpukit/score/include/rtems/score/threadq.h

    r0e1d11f3 r93306058  
    6969   */
    7070  ISR_lock_Context Lock_context;
     71
     72  /**
     73   * @brief The expected thread dispatch disable level for
     74   * _Thread_queue_Enqueue_critical().
     75   *
     76   * In case the actual thread dispatch disable level is not equal to the
     77   * expected level, then a fatal error occurs.
     78   */
     79  uint32_t expected_thread_dispatch_disable_level;
    7180
    7281  /**
  • cpukit/score/include/rtems/score/threadqimpl.h

    r0e1d11f3 r93306058  
    6363)
    6464{
    65 #if defined(RTEMS_MULTIPROCESSING) && defined(RTEMS_DEBUG)
     65#if defined(RTEMS_DEBUG)
     66  queue_context->expected_thread_dispatch_disable_level = 0xdeadbeef;
     67#if defined(RTEMS_MULTIPROCESSING)
    6668  queue_context->mp_callout = NULL;
     69#endif
    6770#else
    6871  (void) queue_context;
    6972#endif
     73}
     74
     75/**
     76 * @brief Sets the expected thread dispatch disable level in the thread queue
     77 * context.
     78 *
     79 * @param queue_context The thread queue context.
     80 * @param expected_level The expected thread dispatch disable level.
     81 *
     82 * @see _Thread_queue_Enqueue_critical().
     83 */
     84RTEMS_INLINE_ROUTINE void
     85_Thread_queue_Context_set_expected_level(
     86  Thread_queue_Context *queue_context,
     87  uint32_t              expected_level
     88)
     89{
     90  queue_context->expected_thread_dispatch_disable_level = expected_level;
    7091}
    7192
     
    310331 * void _Mutex_Obtain( Mutex *mutex )
    311332 * {
    312  *   ISR_lock_Context  lock_context;
    313  *   Thread_Control   *executing;
    314  *
    315  *   _Thread_queue_Acquire( &mutex->Queue, &lock_context );
     333 *   Thread_queue_Context  queue_context;
     334 *   Thread_Control       *executing;
     335 *
     336 *   _Thread_queue_Context_initialize( &queue_context );
     337 *   _Thread_queue_Acquire( &mutex->Queue, &queue_context.Lock_context );
    316338 *
    317339 *   executing = _Thread_Executing;
     
    319341 *   if ( mutex->owner == NULL ) {
    320342 *     mutex->owner = executing;
    321  *     _Thread_queue_Release( &mutex->Queue, &lock_context );
     343 *     _Thread_queue_Release( &mutex->Queue, &queue_context.Lock_context );
    322344 *   } else {
     345 *     _Thread_queue_Context_set_expected_level( &queue_context, 1 );
    323346 *     _Thread_queue_Enqueue_critical(
    324347 *       &mutex->Queue.Queue,
     
    328351 *       WATCHDOG_NO_TIMEOUT,
    329352 *       0,
    330  *       &lock_context
     353 *       &queue_context
    331354 *     );
    332355 *   }
     
    340363 * @param[in] timeout Interval to wait.  Use WATCHDOG_NO_TIMEOUT to block
    341364 * potentially forever.
    342  * @param[in] lock_context The lock context of the lock acquire.
     365 * @param[in] queue_context The thread queue context of the lock acquire.
    343366 */
    344367void _Thread_queue_Enqueue_critical(
     
    348371  States_Control                 state,
    349372  Watchdog_Interval              timeout,
    350   ISR_lock_Context              *lock_context
     373  Thread_queue_Context          *queue_context
    351374);
    352375
     
    360383  Thread_Control                *the_thread,
    361384  States_Control                 state,
    362   Watchdog_Interval              timeout
    363 )
    364 {
    365   ISR_lock_Context lock_context;
    366 
    367   _Thread_queue_Acquire( the_thread_queue, &lock_context );
     385  Watchdog_Interval              timeout,
     386  uint32_t                       expected_level
     387)
     388{
     389  Thread_queue_Context queue_context;
     390
     391  _Thread_queue_Context_initialize( &queue_context );
     392  _Thread_queue_Acquire( the_thread_queue, &queue_context.Lock_context );
     393  _Thread_queue_Context_set_expected_level( &queue_context, expected_level );
    368394  _Thread_queue_Enqueue_critical(
    369395    &the_thread_queue->Queue,
     
    372398    state,
    373399    timeout,
    374     &lock_context
     400    &queue_context
    375401  );
    376402}
  • cpukit/score/src/condition.c

    r0e1d11f3 r93306058  
    5454
    5555static Thread_Control *_Condition_Queue_acquire_critical(
    56   Condition_Control *condition,
    57   ISR_lock_Context  *lock_context
     56  Condition_Control    *condition,
     57  Thread_queue_Context *queue_context
    5858)
    5959{
     
    6464    &condition->Queue.Queue,
    6565    &executing->Potpourri_stats,
    66     lock_context
     66    &queue_context->Lock_context
    6767  );
    6868
     
    7171
    7272static void _Condition_Queue_release(
    73   Condition_Control *condition,
    74   ISR_lock_Context  *lock_context
    75 )
    76 {
    77   _Thread_queue_Queue_release( &condition->Queue.Queue, lock_context );
     73  Condition_Control    *condition,
     74  Thread_queue_Context *queue_context
     75)
     76{
     77  _Thread_queue_Queue_release(
     78    &condition->Queue.Queue,
     79    &queue_context->Lock_context
     80  );
    7881}
    7982
     
    8184  struct _Condition_Control *_condition,
    8285  Watchdog_Interval          timeout,
    83   ISR_lock_Context          *lock_context
     86  Thread_queue_Context      *queue_context
    8487)
    8588{
     
    8992
    9093  condition = _Condition_Get( _condition );
    91   executing = _Condition_Queue_acquire_critical( condition, lock_context );
    92   cpu_self = _Thread_Dispatch_disable_critical( lock_context );
    93 
     94  executing = _Condition_Queue_acquire_critical( condition, queue_context );
     95  cpu_self = _Thread_Dispatch_disable_critical( &queue_context->Lock_context );
     96
     97  _Thread_queue_Context_set_expected_level( queue_context, 2 );
    9498  _Thread_queue_Enqueue_critical(
    9599    &condition->Queue.Queue,
     
    98102    STATES_WAITING_FOR_SYS_LOCK_CONDITION,
    99103    timeout,
    100     lock_context
     104    queue_context
    101105  );
    102106
     
    109113)
    110114{
    111   ISR_lock_Context  lock_context;
    112   Per_CPU_Control  *cpu_self;
    113 
    114   _ISR_lock_ISR_disable( &lock_context );
    115   cpu_self = _Condition_Do_wait( _condition, 0, &lock_context );
     115  Thread_queue_Context  queue_context;
     116  Per_CPU_Control      *cpu_self;
     117
     118  _Thread_queue_Context_initialize( &queue_context );
     119  _ISR_lock_ISR_disable( &queue_context.Lock_context );
     120  cpu_self = _Condition_Do_wait( _condition, 0, &queue_context );
    116121
    117122  _Mutex_Release( _mutex );
     
    126131)
    127132{
    128   ISR_lock_Context   lock_context;
    129   Per_CPU_Control   *cpu_self;
    130   Thread_Control    *executing;
    131   int                eno;
    132   Watchdog_Interval  ticks;
    133 
    134   _ISR_lock_ISR_disable( &lock_context );
     133  Thread_queue_Context  queue_context;
     134  Per_CPU_Control      *cpu_self;
     135  Thread_Control       *executing;
     136  int                   eno;
     137  Watchdog_Interval     ticks;
     138
     139  _Thread_queue_Context_initialize( &queue_context );
     140  _ISR_lock_ISR_disable( &queue_context.Lock_context );
    135141
    136142  switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
    137143    case TOD_ABSOLUTE_TIMEOUT_INVALID:
    138       _ISR_lock_ISR_enable( &lock_context );
     144      _ISR_lock_ISR_enable( &queue_context.Lock_context );
    139145      return EINVAL;
    140146    case TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST:
    141147    case TOD_ABSOLUTE_TIMEOUT_IS_NOW:
    142       _ISR_lock_ISR_enable( &lock_context );
     148      _ISR_lock_ISR_enable( &queue_context.Lock_context );
    143149      return ETIMEDOUT;
    144150    default:
     
    146152  }
    147153
    148   cpu_self = _Condition_Do_wait( _condition, ticks, &lock_context );
     154  cpu_self = _Condition_Do_wait( _condition, ticks, &queue_context );
    149155
    150156  _Mutex_Release( _mutex );
     
    162168)
    163169{
    164   ISR_lock_Context  lock_context;
    165   Per_CPU_Control  *cpu_self;
    166   unsigned int      nest_level;
    167 
    168   _ISR_lock_ISR_disable( &lock_context );
    169   cpu_self = _Condition_Do_wait( _condition, 0, &lock_context );
     170  Thread_queue_Context  queue_context;
     171  Per_CPU_Control      *cpu_self;
     172  unsigned int          nest_level;
     173
     174  _Thread_queue_Context_initialize( &queue_context );
     175  _ISR_lock_ISR_disable( &queue_context.Lock_context );
     176  cpu_self = _Condition_Do_wait( _condition, 0, &queue_context );
    170177
    171178  nest_level = _mutex->_nest_level;
     
    183190)
    184191{
    185   ISR_lock_Context   lock_context;
    186   Per_CPU_Control   *cpu_self;
    187   Thread_Control    *executing;
    188   int                eno;
    189   unsigned int       nest_level;
    190   Watchdog_Interval  ticks;
    191 
    192   _ISR_lock_ISR_disable( &lock_context );
     192  Thread_queue_Context   queue_context;
     193  Per_CPU_Control       *cpu_self;
     194  Thread_Control        *executing;
     195  int                    eno;
     196  unsigned int           nest_level;
     197  Watchdog_Interval      ticks;
     198
     199  _Thread_queue_Context_initialize( &queue_context );
     200  _ISR_lock_ISR_disable( &queue_context.Lock_context );
    193201
    194202  switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
    195203    case TOD_ABSOLUTE_TIMEOUT_INVALID:
    196       _ISR_lock_ISR_enable( &lock_context );
     204      _ISR_lock_ISR_enable( &queue_context.Lock_context );
    197205      return EINVAL;
    198206    case TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST:
    199207    case TOD_ABSOLUTE_TIMEOUT_IS_NOW:
    200       _ISR_lock_ISR_enable( &lock_context );
     208      _ISR_lock_ISR_enable( &queue_context.Lock_context );
    201209      return ETIMEDOUT;
    202210    default:
     
    204212  }
    205213
    206   cpu_self = _Condition_Do_wait( _condition, ticks, &lock_context );
     214  cpu_self = _Condition_Do_wait( _condition, ticks, &queue_context );
    207215
    208216  nest_level = _mutex->_nest_level;
     
    250258  _Thread_queue_Context_initialize( &context.Base );
    251259  _ISR_lock_ISR_disable( &context.Base.Lock_context );
    252   _Condition_Queue_acquire_critical( condition, &context.Base.Lock_context );
     260  _Condition_Queue_acquire_critical( condition, &context.Base );
    253261
    254262  /*
     
    257265   */
    258266  if ( __predict_true( _Thread_queue_Is_empty( &condition->Queue.Queue ) ) ) {
    259     _Condition_Queue_release( condition, &context.Base.Lock_context );
     267    _Condition_Queue_release( condition, &context.Base );
    260268    return;
    261269  }
  • cpukit/score/src/corebarrierwait.c

    r0e1d11f3 r93306058  
    4646  } else {
    4747    the_barrier->number_of_waiting_threads = number_of_waiting_threads;
     48    _Thread_queue_Context_set_expected_level( queue_context, 1 );
    4849    _Thread_queue_Enqueue_critical(
    4950      &the_barrier->Wait_queue.Queue,
     
    5253      STATES_WAITING_FOR_BARRIER,
    5354      timeout,
    54       &queue_context->Lock_context
     55      queue_context
    5556    );
    5657    return _Thread_Wait_get_status( executing );
  • cpukit/score/src/coremsgseize.c

    r0e1d11f3 r93306058  
    115115  /* Wait.count will be filled in with the message priority */
    116116
     117  _Thread_queue_Context_set_expected_level( queue_context, 1 );
    117118  _Thread_queue_Enqueue_critical(
    118119    &the_message_queue->Wait_queue.Queue,
     
    121122    STATES_WAITING_FOR_MESSAGE,
    122123    timeout,
    123     &queue_context->Lock_context
     124    queue_context
    124125  );
    125126  return _Thread_Wait_get_status( executing );
  • cpukit/score/src/coremsgsubmit.c

    r0e1d11f3 r93306058  
    133133    executing->Wait.count = submit_type;
    134134
     135    _Thread_queue_Context_set_expected_level( queue_context, 1 );
    135136    _Thread_queue_Enqueue_critical(
    136137      &the_message_queue->Wait_queue.Queue,
     
    139140      STATES_WAITING_FOR_MESSAGE,
    140141      timeout,
    141       &queue_context->Lock_context
     142      queue_context
    142143    );
    143144    return _Thread_Wait_get_status( executing );
  • cpukit/score/src/coremutexseize.c

    r0e1d11f3 r93306058  
    1919#endif
    2020
    21 #include <rtems/system.h>
    22 #include <rtems/score/isr.h>
    2321#include <rtems/score/coremuteximpl.h>
    2422#include <rtems/score/statesimpl.h>
     
    2624
    2725Status_Control _CORE_mutex_Seize_interrupt_blocking(
    28   CORE_mutex_Control  *the_mutex,
    29   Thread_Control      *executing,
    30   Watchdog_Interval    timeout,
    31   ISR_lock_Context    *lock_context
     26  CORE_mutex_Control   *the_mutex,
     27  Thread_Control       *executing,
     28  Watchdog_Interval     timeout,
     29  Thread_queue_Context *queue_context
    3230)
    3331{
     
    5250     * once we released the lock.
    5351     */
    54     _Thread_queue_Release( &the_mutex->Wait_queue, lock_context );
     52    _CORE_mutex_Release( the_mutex, queue_context );
    5553#endif
    5654
     
    5856
    5957#if !defined(RTEMS_SMP)
    60     _Thread_queue_Acquire( &the_mutex->Wait_queue, lock_context );
     58    _ISR_lock_ISR_disable( &queue_context->Lock_context );
     59    _CORE_mutex_Acquire_critical( the_mutex, queue_context );
    6160#endif
    6261  }
     62
     63#if defined(RTEMS_SMP)
     64  _Thread_queue_Context_set_expected_level( queue_context, 1 );
     65#else
     66  _Thread_queue_Context_set_expected_level( queue_context, 2 );
     67#endif
    6368
    6469  _Thread_queue_Enqueue_critical(
     
    6873    STATES_WAITING_FOR_MUTEX,
    6974    timeout,
    70     lock_context
     75    queue_context
    7176  );
    7277
  • cpukit/score/src/corerwlockobtainread.c

    r0e1d11f3 r93306058  
    8080  executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
    8181
     82  _Thread_queue_Context_set_expected_level( queue_context, 1 );
    8283  _Thread_queue_Enqueue_critical(
    8384     &the_rwlock->Wait_queue.Queue,
     
    8687     STATES_WAITING_FOR_RWLOCK,
    8788     timeout,
    88      &queue_context->Lock_context
     89     queue_context
    8990  );
    9091  return _Thread_Wait_get_status( executing );
  • cpukit/score/src/corerwlockobtainwrite.c

    r0e1d11f3 r93306058  
    6868  executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE;
    6969
     70  _Thread_queue_Context_set_expected_level( queue_context, 1 );
    7071  _Thread_queue_Enqueue_critical(
    7172     &the_rwlock->Wait_queue.Queue,
     
    7475     STATES_WAITING_FOR_RWLOCK,
    7576     timeout,
    76      &queue_context->Lock_context
     77     queue_context
    7778  );
    7879  return _Thread_Wait_get_status( executing );
  • cpukit/score/src/futex.c

    r0e1d11f3 r93306058  
    5151static Thread_Control *_Futex_Queue_acquire(
    5252  Futex_Control    *futex,
    53   ISR_lock_Context *lock_context
     53  Thread_queue_Context *queue_context
    5454)
    5555{
    5656  Thread_Control *executing;
    5757
    58   _ISR_lock_ISR_disable( lock_context );
     58  _ISR_lock_ISR_disable( &queue_context->Lock_context );
    5959  executing = _Thread_Executing;
    6060  _Thread_queue_Queue_acquire_critical(
    6161    &futex->Queue.Queue,
    6262    &executing->Potpourri_stats,
    63     lock_context
     63    &queue_context->Lock_context
    6464  );
    6565
     
    6868
    6969static void _Futex_Queue_release(
    70   Futex_Control    *futex,
    71   ISR_lock_Context *lock_context
     70  Futex_Control        *futex,
     71  Thread_queue_Context *queue_context
    7272)
    7373{
    74   _Thread_queue_Queue_release( &futex->Queue.Queue, lock_context );
     74  _Thread_queue_Queue_release(
     75    &futex->Queue.Queue,
     76    &queue_context->Lock_context
     77  );
    7578}
    7679
    7780int _Futex_Wait( struct _Futex_Control *_futex, int *uaddr, int val )
    7881{
    79   Futex_Control    *futex;
    80   ISR_lock_Context  lock_context;
    81   Thread_Control   *executing;
    82   int               eno;
     82  Futex_Control        *futex;
     83  Thread_queue_Context  queue_context;
     84  Thread_Control       *executing;
     85  int                   eno;
    8386
    8487  futex = _Futex_Get( _futex );
    85   executing = _Futex_Queue_acquire( futex, &lock_context );
     88  executing = _Futex_Queue_acquire( futex, &queue_context );
    8689
    8790  if ( *uaddr == val ) {
     91    _Thread_queue_Context_set_expected_level( &queue_context, 1 );
    8892    _Thread_queue_Enqueue_critical(
    8993      &futex->Queue.Queue,
     
    9296      STATES_WAITING_FOR_SYS_LOCK_FUTEX,
    9397      WATCHDOG_NO_TIMEOUT,
    94       &lock_context
     98      &queue_context
    9599    );
    96100    eno = 0;
    97101  } else {
    98     _Futex_Queue_release( futex, &lock_context );
     102    _Futex_Queue_release( futex, &queue_context );
    99103    eno = EWOULDBLOCK;
    100104  }
     
    129133int _Futex_Wake( struct _Futex_Control *_futex, int count )
    130134{
    131   Futex_Control      *futex;
     135  Futex_Control *futex;
    132136  Futex_Context  context;
    133137
    134138  futex = _Futex_Get( _futex );
    135   _Futex_Queue_acquire( futex, &context.Base.Lock_context );
     139  _Futex_Queue_acquire( futex, &context.Base );
    136140
    137141  /*
     
    141145   */
    142146  if ( __predict_true( _Thread_queue_Is_empty( &futex->Queue.Queue ) ) ) {
    143     _Futex_Queue_release( futex, &context.Base.Lock_context );
     147    _Futex_Queue_release( futex, &context.Base );
    144148    return 0;
    145149  }
  • cpukit/score/src/mpci.c

    r0e1d11f3 r93306058  
    260260      executing,
    261261      STATES_WAITING_FOR_RPC_REPLY | extra_state,
    262       the_packet->timeout
     262      the_packet->timeout,
     263      2
    263264    );
    264265
  • cpukit/score/src/mutex.c

    r0e1d11f3 r93306058  
    7373
    7474static Thread_Control *_Mutex_Queue_acquire(
    75   Mutex_Control    *mutex,
    76   ISR_lock_Context *lock_context
     75  Mutex_Control        *mutex,
     76  Thread_queue_Context *queue_context
    7777)
    7878{
    7979  Thread_Control *executing;
    8080
    81   _ISR_lock_ISR_disable( lock_context );
     81  _ISR_lock_ISR_disable( &queue_context->Lock_context );
    8282  executing = _Thread_Executing;
    8383  _Thread_queue_Queue_acquire_critical(
    8484    &mutex->Queue.Queue,
    8585    &executing->Potpourri_stats,
    86     lock_context
     86    &queue_context->Lock_context
    8787  );
    8888
     
    9191
    9292static void _Mutex_Queue_release(
    93   Mutex_Control    *mutex,
    94   ISR_lock_Context *lock_context
    95 )
    96 {
    97   _Thread_queue_Queue_release( &mutex->Queue.Queue, lock_context );
     93  Mutex_Control        *mutex,
     94  Thread_queue_Context *queue_context
     95)
     96{
     97  _Thread_queue_Queue_release(
     98    &mutex->Queue.Queue,
     99    &queue_context->Lock_context
     100  );
    98101}
    99102
    100103static void _Mutex_Acquire_slow(
    101   Mutex_Control     *mutex,
    102   Thread_Control    *owner,
    103   Thread_Control    *executing,
    104   Watchdog_Interval  timeout,
    105   ISR_lock_Context  *lock_context
     104  Mutex_Control        *mutex,
     105  Thread_Control       *owner,
     106  Thread_Control       *executing,
     107  Watchdog_Interval     timeout,
     108  Thread_queue_Context *queue_context
    106109)
    107110{
    108111  _Thread_Inherit_priority( owner, executing );
     112  _Thread_queue_Context_set_expected_level( queue_context, 1 );
    109113  _Thread_queue_Enqueue_critical(
    110114    &mutex->Queue.Queue,
     
    113117    STATES_WAITING_FOR_SYS_LOCK_MUTEX,
    114118    timeout,
    115     lock_context
     119    queue_context
    116120  );
    117121}
     
    149153    );
    150154  } else {
    151     _Mutex_Queue_release( mutex, &queue_context->Lock_context );
     155    _Mutex_Queue_release( mutex, queue_context );
    152156  }
    153157
     
    186190
    187191  if ( __predict_true( heads == NULL && keep_priority ) ) {
    188     _Mutex_Queue_release( mutex, &queue_context->Lock_context );
     192    _Mutex_Queue_release( mutex, queue_context );
    189193  } else {
    190194    _Mutex_Release_slow(
     
    200204void _Mutex_Acquire( struct _Mutex_Control *_mutex )
    201205{
    202   Mutex_Control    *mutex;
    203   ISR_lock_Context  lock_context;
    204   Thread_Control   *executing;
    205   Thread_Control   *owner;
     206  Mutex_Control        *mutex;
     207  Thread_queue_Context  queue_context;
     208  Thread_Control       *executing;
     209  Thread_Control       *owner;
    206210
    207211  mutex = _Mutex_Get( _mutex );
    208   executing = _Mutex_Queue_acquire( mutex, &lock_context );
     212  _Thread_queue_Context_initialize( &queue_context );
     213  executing = _Mutex_Queue_acquire( mutex, &queue_context );
    209214
    210215  owner = mutex->Queue.Queue.owner;
     
    213218    mutex->Queue.Queue.owner = executing;
    214219    ++executing->resource_count;
    215     _Mutex_Queue_release( mutex, &lock_context );
    216   } else {
    217     _Mutex_Acquire_slow( mutex, owner, executing, 0, &lock_context );
     220    _Mutex_Queue_release( mutex, &queue_context );
     221  } else {
     222    _Mutex_Acquire_slow( mutex, owner, executing, 0, &queue_context );
    218223  }
    219224}
     
    224229)
    225230{
    226   Mutex_Control    *mutex;
    227   ISR_lock_Context  lock_context;
    228   Thread_Control   *executing;
    229   Thread_Control   *owner;
     231  Mutex_Control        *mutex;
     232  Thread_queue_Context  queue_context;
     233  Thread_Control       *executing;
     234  Thread_Control       *owner;
    230235
    231236  mutex = _Mutex_Get( _mutex );
    232   executing = _Mutex_Queue_acquire( mutex, &lock_context );
     237  _Thread_queue_Context_initialize( &queue_context );
     238  executing = _Mutex_Queue_acquire( mutex, &queue_context );
    233239
    234240  owner = mutex->Queue.Queue.owner;
     
    237243    mutex->Queue.Queue.owner = executing;
    238244    ++executing->resource_count;
    239     _Mutex_Queue_release( mutex, &lock_context );
     245    _Mutex_Queue_release( mutex, &queue_context );
    240246
    241247    return 0;
     
    245251    switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
    246252      case TOD_ABSOLUTE_TIMEOUT_INVALID:
    247         _Mutex_Queue_release( mutex, &lock_context );
     253        _Mutex_Queue_release( mutex, &queue_context );
    248254        return EINVAL;
    249255      case TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST:
    250256      case TOD_ABSOLUTE_TIMEOUT_IS_NOW:
    251         _Mutex_Queue_release( mutex, &lock_context );
     257        _Mutex_Queue_release( mutex, &queue_context );
    252258        return ETIMEDOUT;
    253259      default:
     
    255261    }
    256262
    257     _Mutex_Acquire_slow( mutex, owner, executing, ticks, &lock_context );
     263    _Mutex_Acquire_slow( mutex, owner, executing, ticks, &queue_context );
    258264
    259265    return STATUS_GET_POSIX( _Thread_Wait_get_status( executing ) );
     
    262268
    263269int _Mutex_Try_acquire( struct _Mutex_Control *_mutex )
    264 {
    265   Mutex_Control    *mutex;
    266   ISR_lock_Context  lock_context;
    267   Thread_Control   *executing;
    268   Thread_Control   *owner;
    269   int               eno;
    270 
    271   mutex = _Mutex_Get( _mutex );
    272   executing = _Mutex_Queue_acquire( mutex, &lock_context );
    273 
    274   owner = mutex->Queue.Queue.owner;
    275 
    276   if ( __predict_true( owner == NULL ) ) {
    277     mutex->Queue.Queue.owner = executing;
    278     ++executing->resource_count;
    279     eno = 0;
    280   } else {
    281     eno = EBUSY;
    282   }
    283 
    284   _Mutex_Queue_release( mutex, &lock_context );
    285 
    286   return eno;
    287 }
    288 
    289 void _Mutex_Release( struct _Mutex_Control *_mutex )
    290270{
    291271  Mutex_Control        *mutex;
    292272  Thread_queue_Context  queue_context;
    293273  Thread_Control       *executing;
     274  Thread_Control       *owner;
     275  int                   eno;
    294276
    295277  mutex = _Mutex_Get( _mutex );
    296278  _Thread_queue_Context_initialize( &queue_context );
    297   executing = _Mutex_Queue_acquire( mutex, &queue_context.Lock_context );
     279  executing = _Mutex_Queue_acquire( mutex, &queue_context );
     280
     281  owner = mutex->Queue.Queue.owner;
     282
     283  if ( __predict_true( owner == NULL ) ) {
     284    mutex->Queue.Queue.owner = executing;
     285    ++executing->resource_count;
     286    eno = 0;
     287  } else {
     288    eno = EBUSY;
     289  }
     290
     291  _Mutex_Queue_release( mutex, &queue_context );
     292
     293  return eno;
     294}
     295
     296void _Mutex_Release( struct _Mutex_Control *_mutex )
     297{
     298  Mutex_Control        *mutex;
     299  Thread_queue_Context  queue_context;
     300  Thread_Control       *executing;
     301
     302  mutex = _Mutex_Get( _mutex );
     303  _Thread_queue_Context_initialize( &queue_context );
     304  executing = _Mutex_Queue_acquire( mutex, &queue_context );
    298305
    299306  _Assert( mutex->Queue.Queue.owner == executing );
     
    312319{
    313320  Mutex_recursive_Control *mutex;
    314   ISR_lock_Context         lock_context;
     321  Thread_queue_Context     queue_context;
    315322  Thread_Control          *executing;
    316323  Thread_Control          *owner;
    317324
    318325  mutex = _Mutex_recursive_Get( _mutex );
    319   executing = _Mutex_Queue_acquire( &mutex->Mutex, &lock_context );
     326  _Thread_queue_Context_initialize( &queue_context );
     327  executing = _Mutex_Queue_acquire( &mutex->Mutex, &queue_context );
    320328
    321329  owner = mutex->Mutex.Queue.Queue.owner;
     
    324332    mutex->Mutex.Queue.Queue.owner = executing;
    325333    ++executing->resource_count;
    326     _Mutex_Queue_release( &mutex->Mutex, &lock_context );
     334    _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    327335  } else if ( owner == executing ) {
    328336    ++mutex->nest_level;
    329     _Mutex_Queue_release( &mutex->Mutex, &lock_context );
    330   } else {
    331     _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, 0, &lock_context );
     337    _Mutex_Queue_release( &mutex->Mutex, &queue_context );
     338  } else {
     339    _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, 0, &queue_context );
    332340  }
    333341}
     
    339347{
    340348  Mutex_recursive_Control *mutex;
    341   ISR_lock_Context         lock_context;
     349  Thread_queue_Context     queue_context;
    342350  Thread_Control          *executing;
    343351  Thread_Control          *owner;
    344352
    345353  mutex = _Mutex_recursive_Get( _mutex );
    346   executing = _Mutex_Queue_acquire( &mutex->Mutex, &lock_context );
     354  _Thread_queue_Context_initialize( &queue_context );
     355  executing = _Mutex_Queue_acquire( &mutex->Mutex, &queue_context );
    347356
    348357  owner = mutex->Mutex.Queue.Queue.owner;
     
    351360    mutex->Mutex.Queue.Queue.owner = executing;
    352361    ++executing->resource_count;
    353     _Mutex_Queue_release( &mutex->Mutex, &lock_context );
     362    _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    354363
    355364    return 0;
    356365  } else if ( owner == executing ) {
    357366    ++mutex->nest_level;
    358     _Mutex_Queue_release( &mutex->Mutex, &lock_context );
     367    _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    359368
    360369    return 0;
     
    364373    switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
    365374      case TOD_ABSOLUTE_TIMEOUT_INVALID:
    366         _Mutex_Queue_release( &mutex->Mutex, &lock_context );
     375        _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    367376        return EINVAL;
    368377      case TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST:
    369378      case TOD_ABSOLUTE_TIMEOUT_IS_NOW:
    370         _Mutex_Queue_release( &mutex->Mutex, &lock_context );
     379        _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    371380        return ETIMEDOUT;
    372381      default:
     
    379388      executing,
    380389      ticks,
    381       &lock_context
     390      &queue_context
    382391    );
    383392
     
    389398{
    390399  Mutex_recursive_Control *mutex;
    391   ISR_lock_Context         lock_context;
     400  Thread_queue_Context     queue_context;
    392401  Thread_Control          *executing;
    393402  Thread_Control          *owner;
     
    395404
    396405  mutex = _Mutex_recursive_Get( _mutex );
    397   executing = _Mutex_Queue_acquire( &mutex->Mutex, &lock_context );
     406  _Thread_queue_Context_initialize( &queue_context );
     407  executing = _Mutex_Queue_acquire( &mutex->Mutex, &queue_context );
    398408
    399409  owner = mutex->Mutex.Queue.Queue.owner;
     
    410420  }
    411421
    412   _Mutex_Queue_release( &mutex->Mutex, &lock_context );
     422  _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    413423
    414424  return eno;
     
    424434  mutex = _Mutex_recursive_Get( _mutex );
    425435  _Thread_queue_Context_initialize( &queue_context );
    426   executing = _Mutex_Queue_acquire(
    427     &mutex->Mutex,
    428     &queue_context.Lock_context
    429   );
     436  executing = _Mutex_Queue_acquire( &mutex->Mutex, &queue_context );
    430437
    431438  _Assert( mutex->Mutex.Queue.Queue.owner == executing );
     
    438445    mutex->nest_level = nest_level - 1;
    439446
    440     _Mutex_Queue_release( &mutex->Mutex, &queue_context.Lock_context );
     447    _Mutex_Queue_release( &mutex->Mutex, &queue_context );
    441448  }
    442449}
  • cpukit/score/src/semaphore.c

    r0e1d11f3 r93306058  
    5757
    5858static Thread_Control *_Semaphore_Queue_acquire(
    59   Semaphore_Control *sem,
    60   ISR_lock_Context  *lock_context
     59  Semaphore_Control    *sem,
     60  Thread_queue_Context *queue_context
    6161)
    6262{
    6363  Thread_Control *executing;
    6464
    65   _ISR_lock_ISR_disable( lock_context );
     65  _ISR_lock_ISR_disable( &queue_context->Lock_context );
    6666  executing = _Thread_Executing;
    6767  _Thread_queue_Queue_acquire_critical(
    6868    &sem->Queue.Queue,
    6969    &executing->Potpourri_stats,
    70     lock_context
     70    &queue_context->Lock_context
    7171  );
    7272
     
    7575
    7676static void _Semaphore_Queue_release(
    77   Semaphore_Control *sem,
    78   ISR_lock_Context  *lock_context
     77  Semaphore_Control    *sem,
     78  Thread_queue_Context *queue_context
    7979)
    8080{
    81   _Thread_queue_Queue_release( &sem->Queue.Queue, lock_context );
     81  _Thread_queue_Queue_release(
     82    &sem->Queue.Queue,
     83    &queue_context->Lock_context
     84  );
    8285}
    8386
    8487void _Semaphore_Wait( struct _Semaphore_Control *_sem )
    8588{
    86   Semaphore_Control *sem ;
    87   ISR_lock_Context   lock_context;
    88   Thread_Control    *executing;
    89   unsigned int       count;
     89  Semaphore_Control    *sem ;
     90  Thread_queue_Context  queue_context;
     91  Thread_Control       *executing;
     92  unsigned int          count;
    9093
    9194  sem = _Semaphore_Get( _sem );
    92   executing = _Semaphore_Queue_acquire( sem, &lock_context );
     95  _Thread_queue_Context_initialize( &queue_context );
     96  executing = _Semaphore_Queue_acquire( sem, &queue_context );
    9397
    9498  count = sem->count;
    9599  if ( count > 0 ) {
    96100    sem->count = count - 1;
    97     _Semaphore_Queue_release( sem, &lock_context );
     101    _Semaphore_Queue_release( sem, &queue_context );
    98102  } else {
     103    _Thread_queue_Context_set_expected_level( &queue_context, 1 );
    99104    _Thread_queue_Enqueue_critical(
    100105      &sem->Queue.Queue,
     
    103108      STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE,
    104109      WATCHDOG_NO_TIMEOUT,
    105       &lock_context
     110      &queue_context
    106111    );
    107112  }
     
    116121  sem = _Semaphore_Get( _sem );
    117122  _Thread_queue_Context_initialize( &queue_context );
    118   _Semaphore_Queue_acquire( sem, &queue_context.Lock_context );
     123  _Semaphore_Queue_acquire( sem, &queue_context );
    119124
    120125  heads = sem->Queue.Queue.heads;
     
    122127    _Assert( sem->count < UINT_MAX );
    123128    ++sem->count;
    124     _Semaphore_Queue_release( sem, &queue_context.Lock_context );
     129    _Semaphore_Queue_release( sem, &queue_context );
    125130  } else {
    126131    const Thread_queue_Operations *operations;
  • cpukit/score/src/threadqenqueue.c

    r0e1d11f3 r93306058  
    4141  States_Control                 state,
    4242  Watchdog_Interval              timeout,
    43   ISR_lock_Context              *lock_context
     43  Thread_queue_Context          *queue_context
    4444)
    4545{
     
    6262
    6363  _Thread_Wait_flags_set( the_thread, THREAD_QUEUE_INTEND_TO_BLOCK );
    64   cpu_self = _Thread_Dispatch_disable_critical( lock_context );
    65   _Thread_queue_Queue_release( queue, lock_context );
     64  cpu_self = _Thread_Dispatch_disable_critical( &queue_context->Lock_context );
     65  _Thread_queue_Queue_release( queue, &queue_context->Lock_context );
     66
     67  if (
     68    cpu_self->thread_dispatch_disable_level
     69      != queue_context->expected_thread_dispatch_disable_level
     70  ) {
     71    _Terminate(
     72      INTERNAL_ERROR_CORE,
     73      false,
     74      INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_FROM_BAD_STATE
     75    );
     76  }
    6677
    6778  /*
  • cpukit/score/src/threadrestart.c

    r0e1d11f3 r93306058  
    444444
    445445void _Thread_Join(
    446   Thread_Control   *the_thread,
    447   States_Control    waiting_for_join,
    448   Thread_Control   *executing,
    449   ISR_lock_Context *lock_context
     446  Thread_Control       *the_thread,
     447  States_Control        waiting_for_join,
     448  Thread_Control       *executing,
     449  Thread_queue_Context *queue_context
    450450)
    451451{
     
    463463    waiting_for_join,
    464464    WATCHDOG_NO_TIMEOUT,
    465     lock_context
     465    queue_context
    466466  );
    467467}
     
    525525void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
    526526{
    527   ISR_lock_Context lock_context;
    528 
    529   _Thread_State_acquire( the_thread, &lock_context );
     527  Thread_queue_Context queue_context;
     528
     529  _Thread_queue_Context_initialize( &queue_context );
     530  _Thread_queue_Context_set_expected_level( &queue_context, 2 );
     531  _Thread_State_acquire( the_thread, &queue_context.Lock_context );
    530532  _Thread_Join(
    531533    the_thread,
    532534    STATES_WAITING_FOR_JOIN,
    533535    executing,
    534     &lock_context
     536    &queue_context
    535537  );
    536538  _Thread_Cancel( the_thread, executing, NULL );
  • testsuites/sptests/spfatal03/testcase.h

    r0e1d11f3 r93306058  
    1717#define FATAL_ERROR_EXPECTED_IS_INTERNAL FALSE
    1818#define FATAL_ERROR_EXPECTED_ERROR       \
    19           INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE
     19          INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_FROM_BAD_STATE
    2020
    2121void force_error(void)
     
    2727  status = rtems_semaphore_create(
    2828    rtems_build_name( 'S','0',' ',' '),
    29     1,
     29    0,
    3030    RTEMS_LOCAL|
    3131    RTEMS_SIMPLE_BINARY_SEMAPHORE,
     
    3838  printk("Obtain semaphore in dispatching critical section\n");
    3939  _Thread_Dispatch_disable();
    40   status = rtems_semaphore_obtain( mutex, RTEMS_DEFAULT_OPTIONS, 0 );
     40  status = rtems_semaphore_obtain( mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
    4141  /* !!! SHOULD NOT RETURN FROM THE ABOVE CALL */
    4242
Note: See TracChangeset for help on using the changeset viewer.