Changeset 742b399 in rtems for cpukit/score/src/coremutex.c


Ignore:
Timestamp:
06/03/96 21:08:26 (28 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
552a345d
Parents:
f39b01e
Message:

added priority ceiling support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/coremutex.c

    rf39b01e r742b399  
    4141 *  Output parameters:  NONE
    4242 */
    43  
     43
    4444void _CORE_mutex_Initialize(
    4545  CORE_mutex_Control           *the_mutex,
     
    5858  the_mutex->Attributes = *the_mutex_attributes;
    5959  the_mutex->lock          = initial_lock;
    60  
     60
    6161  if ( initial_lock == CORE_MUTEX_LOCKED ) {
    6262    the_mutex->nest_count = 1;
     
    145145  _ISR_Enable( level );
    146146
    147   if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) &&
    148     the_mutex->holder->current_priority >
    149                                       _Thread_Executing->current_priority ) {
    150     _Thread_Change_priority(
    151     the_mutex->holder, _Thread_Executing->current_priority );
     147  switch ( the_mutex->Attributes.discipline ) {
     148    case CORE_MUTEX_DISCIPLINES_FIFO:
     149    case CORE_MUTEX_DISCIPLINES_PRIORITY:
     150    case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
     151      break;
     152    case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
     153      if ( the_mutex->holder->current_priority > executing->current_priority ) {
     154        _Thread_Change_priority(
     155          the_mutex->holder,
     156          executing->current_priority
     157        );
     158      }
     159      break;
    152160  }
    153161
    154162  _Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout );
     163
     164  if ( _Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL ) {
     165    switch ( the_mutex->Attributes.discipline ) {
     166      case CORE_MUTEX_DISCIPLINES_FIFO:
     167      case CORE_MUTEX_DISCIPLINES_PRIORITY:
     168      case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
     169        break;
     170      case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
     171        _Thread_Change_priority(
     172          executing,
     173          the_mutex->Attributes.priority_ceiling
     174        );
     175        break;
     176    }
     177  }
    155178}
    156179
     
    173196 *    core error code              - if unsuccessful
    174197 */
    175  
     198
    176199CORE_mutex_Status _CORE_mutex_Surrender(
    177200  CORE_mutex_Control                *the_mutex,
     
    181204{
    182205  Thread_Control *the_thread;
     206  Thread_Control *executing;
     207
     208  executing = _Thread_Executing;
    183209
    184210  if ( !_Objects_Are_ids_equal(
    185211           _Thread_Executing->Object.id, the_mutex->holder_id ) )
    186212    return( CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE );
    187  
     213
    188214  the_mutex->nest_count--;
    189  
     215
    190216  if ( the_mutex->nest_count != 0 )
    191217    return( CORE_MUTEX_STATUS_SUCCESSFUL );
    192  
     218
    193219  _Thread_Executing->resource_count--;
    194220  the_mutex->holder    = NULL;
    195221  the_mutex->holder_id = 0;
    196  
     222
    197223  /*
    198224   *  Whether or not someone is waiting for the mutex, an
     
    200226   *  mutex (i.e. resource) this task has.
    201227   */
    202  
    203   if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) &&
    204           _Thread_Executing->resource_count == 0 &&
    205           _Thread_Executing->real_priority !=
    206           _Thread_Executing->current_priority ) {
    207      _Thread_Change_priority(
    208        _Thread_Executing,
    209        _Thread_Executing->real_priority
    210      );
    211   }
     228
     229  switch ( the_mutex->Attributes.discipline ) {
     230    case CORE_MUTEX_DISCIPLINES_FIFO:
     231    case CORE_MUTEX_DISCIPLINES_PRIORITY:
     232      break;
     233    case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
     234    case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
     235      if ( executing->resource_count == 0 &&
     236           executing->real_priority !=
     237           executing->current_priority ) {
     238         _Thread_Change_priority( executing, executing->real_priority );
     239      }
     240      break;
     241  }
     242
    212243
    213244  if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
    214  
     245
    215246    if ( !_Objects_Is_local_id( the_thread->Object.id ) ) {
    216247     
     
    218249      the_mutex->holder_id  = the_thread->Object.id;
    219250      the_mutex->nest_count = 1;
    220  
     251
    221252      ( *api_mutex_mp_support)( the_thread, id );
    222253
    223254    } else {
    224  
     255
    225256      the_mutex->holder     = the_thread;
    226257      the_mutex->holder_id  = the_thread->Object.id;
    227258      the_thread->resource_count++;
    228259      the_mutex->nest_count = 1;
    229  
     260
    230261     /*
    231       *  No special action for priority inheritance because the_thread
    232       *  is guaranteed to be the highest priority thread waiting for
    233       *  the mutex.
     262      *  No special action for priority inheritance or priority ceiling
     263      *  because the_thread is guaranteed to be the highest priority
     264      *  thread waiting for the mutex.
    234265      */
    235266    }
    236267  } else
    237268    the_mutex->lock = CORE_MUTEX_UNLOCKED;
    238  
     269
    239270  return( CORE_MUTEX_STATUS_SUCCESSFUL );
    240271}
     
    253284 *  Output parameters:  NONE
    254285 */
    255  
     286
    256287void _CORE_mutex_Flush(
    257288  CORE_mutex_Control         *the_mutex,
     
    260291)
    261292{
    262  
    263293  _Thread_queue_Flush(
    264294    &the_mutex->Wait_queue,
     
    266296    status
    267297  );
    268  
    269 }
     298}
Note: See TracChangeset for help on using the changeset viewer.