Changeset e76c517 in rtems


Ignore:
Timestamp:
May 1, 2015, 6:52:51 PM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
cfa5aab
Parents:
cc18d7b
git-author:
Sebastian Huber <sebastian.huber@…> (05/01/15 18:52:51)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/19/15 10:00:46)
Message:

score: Fine grained locking for semaphores

Update #2273.

Location:
cpukit
Files:
7 edited

Legend:

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

    rcc18d7b re76c517  
    9090}
    9191
     92RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
     93_POSIX_Semaphore_Get_interrupt_disable(
     94  sem_t             *id,
     95  Objects_Locations *location,
     96  ISR_lock_Context  *lock_context
     97)
     98{
     99  return (POSIX_Semaphore_Control *) _Objects_Get_isr_disable(
     100    &_POSIX_Semaphore_Information,
     101    (Objects_Id)*id,
     102    location,
     103    lock_context
     104  );
     105}
    92106
    93107/**
  • cpukit/posix/src/sempost.c

    rcc18d7b re76c517  
    3838  POSIX_Semaphore_Control          *the_semaphore;
    3939  Objects_Locations                 location;
     40  ISR_lock_Context                  lock_context;
    4041
    41   the_semaphore = _POSIX_Semaphore_Get( sem, &location );
     42  the_semaphore = _POSIX_Semaphore_Get_interrupt_disable(
     43    sem,
     44    &location,
     45    &lock_context
     46  );
    4247  switch ( location ) {
    4348
     
    4752        the_semaphore->Object.id,
    4853#if defined(RTEMS_MULTIPROCESSING)
    49         NULL         /* POSIX Semaphores are local only */
     54        NULL,        /* POSIX Semaphores are local only */
    5055#else
    51         NULL
     56        NULL,
    5257#endif
     58        &lock_context
    5359      );
    54       _Objects_Put( &the_semaphore->Object );
    5560      return 0;
    5661
  • cpukit/rtems/src/semobtain.c

    rcc18d7b re76c517  
    5757      wait = !_Options_Is_no_wait( option_set );
    5858#if defined(RTEMS_SMP)
    59       _Thread_Disable_dispatch();
    6059      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
    6160        MRSP_Status mrsp_status;
    6261
     62        _Thread_Disable_dispatch();
    6363        _ISR_lock_ISR_enable( &lock_context );
    6464        mrsp_status = _MRSP_Obtain(
     
    7474#endif
    7575      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
     76#if defined(RTEMS_SMP)
     77        _Thread_Disable_dispatch();
     78#endif
    7679        _CORE_mutex_Seize(
    7780          &the_semaphore->Core_control.mutex,
     
    99102        &lock_context
    100103      );
    101 #if defined(RTEMS_SMP)
    102       _Thread_Enable_dispatch();
    103 #endif
    104       _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
    105104      return _Semaphore_Translate_core_semaphore_return_code(
    106105                  executing->Wait.return_code );
  • cpukit/rtems/src/semrelease.c

    rcc18d7b re76c517  
    6363  CORE_semaphore_Status       semaphore_status;
    6464  rtems_attribute             attribute_set;
     65  ISR_lock_Context            lock_context;
    6566
    66   the_semaphore = _Semaphore_Get( id, &location );
     67  the_semaphore = _Semaphore_Get_interrupt_disable(
     68    id,
     69    &location,
     70    &lock_context
     71  );
    6772  switch ( location ) {
    6873
     
    7176#if defined(RTEMS_SMP)
    7277      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
     78        _Thread_Disable_dispatch();
     79        _ISR_lock_ISR_enable( &lock_context );
    7380        MRSP_Status mrsp_status = _MRSP_Release(
    7481          &the_semaphore->Core_control.mrsp,
    7582          _Thread_Get_executing()
    7683        );
    77         _Objects_Put( &the_semaphore->Object );
     84        _Thread_Enable_dispatch();
    7885        return _Semaphore_Translate_MRSP_status_code( mrsp_status );
    7986      } else
    8087#endif
    8188      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
     89        _Thread_Disable_dispatch();
     90        _ISR_lock_ISR_enable( &lock_context );
    8291        mutex_status = _CORE_mutex_Surrender(
    8392          &the_semaphore->Core_control.mutex,
     
    8594          MUTEX_MP_SUPPORT
    8695        );
    87         _Objects_Put( &the_semaphore->Object );
     96        _Thread_Enable_dispatch();
    8897        return _Semaphore_Translate_core_mutex_return_code( mutex_status );
    8998      } else {
     
    91100          &the_semaphore->Core_control.semaphore,
    92101          id,
    93           MUTEX_MP_SUPPORT
     102          MUTEX_MP_SUPPORT,
     103          &lock_context
    94104        );
    95         _Objects_Put( &the_semaphore->Object );
    96105        return
    97106          _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
  • cpukit/score/include/rtems/score/coresemimpl.h

    rcc18d7b re76c517  
    142142 *  @param[in] api_semaphore_mp_support is the routine to invoke if the
    143143 *         thread unblocked is remote
     144 *  @param[in] lock_context is a temporary variable used to contain the ISR
     145 *        disable level cookie
    144146 *
    145147 *  @retval an indication of whether the routine succeeded or failed
     
    148150  CORE_semaphore_Control                *the_semaphore,
    149151  Objects_Id                             id,
    150   CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support
     152  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support,
     153  ISR_lock_Context                      *lock_context
    151154);
    152155
     
    229232
    230233  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
     234  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
    231235  if ( the_semaphore->count != 0 ) {
    232236    the_semaphore->count -= 1;
    233     _ISR_lock_ISR_enable( lock_context );
     237    _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
    234238    return;
    235239  }
    236240
    237241  if ( !wait ) {
    238     _ISR_lock_ISR_enable( lock_context );
     242    _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
    239243    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
    240244    return;
    241245  }
    242246
    243   _Thread_Disable_dispatch();
    244247  executing->Wait.id = id;
    245   _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
    246248  _Thread_queue_Enqueue_critical(
    247249    &the_semaphore->Wait_queue,
     
    252254    lock_context
    253255  );
    254   _Thread_Enable_dispatch();
    255256}
    256257
  • cpukit/score/src/coresemsurrender.c

    rcc18d7b re76c517  
    2121
    2222#include <rtems/score/coresemimpl.h>
    23 #include <rtems/score/objectimpl.h>
    2423
    2524CORE_semaphore_Status _CORE_semaphore_Surrender(
    2625  CORE_semaphore_Control                *the_semaphore,
    2726  Objects_Id                             id,
    28   CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support
     27  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support,
     28  ISR_lock_Context                      *lock_context
    2929)
    3030{
    3131  Thread_Control *the_thread;
    32   ISR_Level       level;
    3332  CORE_semaphore_Status status;
    3433
    3534  status = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
    3635
    37   if ( (the_thread = _Thread_queue_Dequeue(&the_semaphore->Wait_queue)) ) {
     36  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
     37
     38  the_thread = _Thread_queue_First_locked( &the_semaphore->Wait_queue );
     39  if ( the_thread != NULL ) {
     40#if defined(RTEMS_MULTIPROCESSING)
     41    _Thread_Dispatch_disable();
     42#endif
     43
     44    _Thread_queue_Extract_critical(
     45      &the_semaphore->Wait_queue,
     46      the_thread,
     47      lock_context
     48    );
    3849
    3950#if defined(RTEMS_MULTIPROCESSING)
    4051    if ( !_Objects_Is_local_id( the_thread->Object.id ) )
    4152      (*api_semaphore_mp_support) ( the_thread, id );
     53
     54    _Thread_Dispatch_enable( _Per_CPU_Get() );
    4255#endif
     56  } else {
     57    if ( the_semaphore->count < the_semaphore->Attributes.maximum_count )
     58      the_semaphore->count += 1;
     59    else
     60      status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED;
    4361
    44   } else {
    45     _ISR_Disable( level );
    46       if ( the_semaphore->count < the_semaphore->Attributes.maximum_count )
    47         the_semaphore->count += 1;
    48       else
    49         status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED;
    50     _ISR_Enable( level );
     62    _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
    5163  }
    5264
  • cpukit/score/src/mpci.c

    rcc18d7b re76c517  
    330330void _MPCI_Announce ( void )
    331331{
    332   _Thread_Disable_dispatch();
    333   (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
    334   _Thread_Enable_dispatch();
     332  ISR_lock_Context lock_context;
     333
     334  _ISR_lock_ISR_disable( &lock_context );
     335  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0, &lock_context );
    335336}
    336337
Note: See TracChangeset for help on using the changeset viewer.