Changeset 48b04fc3 in rtems


Ignore:
Timestamp:
Apr 19, 2016, 4:28:03 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
adbedd1
Parents:
bbe654af
git-author:
Sebastian Huber <sebastian.huber@…> (04/19/16 04:28:03)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/21/16 05:29:39)
Message:

posix: Avoid Giant lock for mutexes

Delete _POSIX_Mutex_Get(). Use _POSIX_Mutex_Get_interrupt_disable()
instead.

Update #2555.

Files:
9 edited

Legend:

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

    rbbe654af r48b04fc3  
    6767)
    6868{
    69   _CORE_mutex_Destroy( &the_mutex->Mutex );
    7069  _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object );
    7170}
     
    121120
    122121/**
    123  *  @brief POSIX Mutex Get (Thread Dispatch Disable)
    124  *
    125  *  A support routine which translates the mutex id into a local pointer.
    126  *  As a side-effect, it may create the mutex.
    127  *
    128  *  @note This version of the method uses a dispatching critical section.
    129  */
    130 POSIX_Mutex_Control *_POSIX_Mutex_Get (
    131   pthread_mutex_t   *mutex,
    132   Objects_Locations *location
    133 );
    134 
    135 /**
    136122 *  @brief POSIX Mutex Get (Interrupt Disable)
    137123 *
  • cpukit/posix/src/mutexdestroy.c

    rbbe654af r48b04fc3  
    1919#endif
    2020
    21 #include <errno.h>
    22 #include <pthread.h>
    23 
    24 #include <rtems/system.h>
    25 #include <rtems/score/coremuteximpl.h>
    26 #include <rtems/score/watchdog.h>
    2721#include <rtems/posix/muteximpl.h>
    28 #include <rtems/posix/priorityimpl.h>
    2922
    3023/*
     
    3629)
    3730{
    38   register POSIX_Mutex_Control *the_mutex;
    39   Objects_Locations             location;
     31  POSIX_Mutex_Control *the_mutex;
     32  ISR_lock_Context     lock_context;
     33  int                  eno;
    4034
    4135  _Objects_Allocator_lock();
    42   the_mutex = _POSIX_Mutex_Get( mutex, &location );
    43   switch ( location ) {
    4436
    45     case OBJECTS_LOCAL:
    46        /*
    47         * XXX: There is an error for the mutex being locked
    48         *  or being in use by a condition variable.
    49         */
     37  the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
    5038
    51       if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
    52         _Objects_Put( &the_mutex->Object );
    53         _Objects_Allocator_unlock();
    54         return EBUSY;
    55       }
     39  if ( the_mutex != NULL ) {
     40    _CORE_mutex_Acquire_critical( &the_mutex->Mutex, &lock_context );
    5641
     42    /*
     43     * XXX: There is an error for the mutex being locked
     44     *  or being in use by a condition variable.
     45     */
     46
     47    if ( !_CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
    5748      _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object );
    58       _CORE_mutex_Flush( &the_mutex->Mutex, EINVAL, NULL, 0 );
    59       _Objects_Put( &the_mutex->Object );
     49      _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
     50      _CORE_mutex_Destroy( &the_mutex->Mutex );
    6051      _POSIX_Mutex_Free( the_mutex );
    61       _Objects_Allocator_unlock();
    62 
    63       return 0;
    64 
    65 #if defined(RTEMS_MULTIPROCESSING)
    66     case OBJECTS_REMOTE:
    67 #endif
    68     case OBJECTS_ERROR:
    69       break;
     52      eno = 0;
     53    } else {
     54      _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
     55      eno = EBUSY;
     56    }
     57  } else {
     58    eno = EINVAL;
    7059  }
    7160
    7261  _Objects_Allocator_unlock();
    73 
    74   return EINVAL;
     62  return eno;
    7563}
  • cpukit/posix/src/mutexget.c

    rbbe654af r48b04fc3  
    2222#include <rtems/score/apimutex.h>
    2323
    24 static bool _POSIX_Mutex_Check_id_and_auto_init(
    25   pthread_mutex_t   *mutex,
    26   Objects_Locations *location
    27 )
     24static bool _POSIX_Mutex_Check_id_and_auto_init( pthread_mutex_t *mutex )
    2825{
    2926  if ( mutex == NULL ) {
    30     *location = OBJECTS_ERROR;
    31 
    3227    return false;
    3328  }
     
    4742
    4843    if ( eno != 0 ) {
    49       *location = OBJECTS_ERROR;
    50 
    5144      return false;
    5245    }
     
    5447
    5548  return true;
    56 }
    57 
    58 POSIX_Mutex_Control *_POSIX_Mutex_Get (
    59   pthread_mutex_t   *mutex,
    60   Objects_Locations *location
    61 )
    62 {
    63   if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, location ) ) {
    64     return NULL;
    65   }
    66 
    67   return (POSIX_Mutex_Control *)
    68     _Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
    6949}
    7050
     
    7656  Objects_Locations location;
    7757
    78   if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, &location ) ) {
     58  if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex ) ) {
    7959    return NULL;
    8060  }
  • cpukit/posix/src/mutexgetprioceiling.c

    rbbe654af r48b04fc3  
    1919#endif
    2020
    21 #include <errno.h>
    22 #include <pthread.h>
    23 
    24 #include <rtems/system.h>
    25 #include <rtems/score/coremuteximpl.h>
    26 #include <rtems/score/watchdog.h>
    2721#include <rtems/posix/muteximpl.h>
    2822#include <rtems/posix/priorityimpl.h>
     
    3731)
    3832{
    39   register POSIX_Mutex_Control *the_mutex;
    40   Objects_Locations             location;
     33  POSIX_Mutex_Control *the_mutex;
     34  ISR_lock_Context     lock_context;
    4135
    42   if ( !prioceiling )
     36  if ( prioceiling == NULL ) {
    4337    return EINVAL;
    44 
    45   the_mutex = _POSIX_Mutex_Get( mutex, &location );
    46   switch ( location ) {
    47 
    48     case OBJECTS_LOCAL:
    49       *prioceiling = _POSIX_Priority_From_core(
    50         the_mutex->Mutex.Attributes.priority_ceiling
    51       );
    52       _Objects_Put( &the_mutex->Object );
    53       return 0;
    54 
    55 #if defined(RTEMS_MULTIPROCESSING)
    56     case OBJECTS_REMOTE:
    57 #endif
    58     case OBJECTS_ERROR:
    59       break;
    6038  }
    6139
    62   return EINVAL;
     40  the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
     41
     42  if ( the_mutex == NULL ) {
     43    return EINVAL;
     44  }
     45
     46  _CORE_mutex_Acquire_critical( &the_mutex->Mutex, &lock_context );
     47
     48  *prioceiling = _POSIX_Priority_From_core(
     49    the_mutex->Mutex.Attributes.priority_ceiling
     50  );
     51
     52  _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
     53
     54  return 0;
    6355}
  • cpukit/posix/src/mutexinit.c

    rbbe654af r48b04fc3  
    1919#endif
    2020
    21 #include <errno.h>
    22 #include <pthread.h>
    23 
    24 #include <rtems/system.h>
    25 #include <rtems/score/coremuteximpl.h>
    26 #include <rtems/score/watchdog.h>
    2721#include <rtems/posix/muteximpl.h>
    2822#include <rtems/posix/priorityimpl.h>
  • cpukit/posix/src/mutexsetprioceiling.c

    rbbe654af r48b04fc3  
    2020
    2121#include <rtems/posix/muteximpl.h>
     22#include <rtems/posix/priorityimpl.h>
    2223
    2324/*
  • testsuites/psxtests/psx09/init.c

    rbbe654af r48b04fc3  
    5050}
    5151
     52static void *mutex_lock_task(void *arg)
     53{
     54  pthread_mutex_t *mtx;
     55  int              eno;
     56
     57  mtx = arg;
     58
     59  eno = pthread_mutex_lock( mtx );
     60  rtems_test_assert( eno == 0 );
     61
     62  sched_yield();
     63
     64  eno = pthread_mutex_unlock( mtx );
     65  rtems_test_assert( eno == 0 );
     66
     67  return NULL;
     68}
     69
     70static void test_destroy_locked_mutex(void)
     71{
     72  pthread_mutex_t mtx;
     73  pthread_t       th;
     74  int             eno;
     75
     76  eno = pthread_mutex_init( &mtx, NULL );
     77  rtems_test_assert( eno == 0 );
     78
     79  eno = pthread_create( &th, NULL, mutex_lock_task, &mtx );
     80  rtems_test_assert( eno == 0 );
     81
     82  sched_yield();
     83
     84  eno = pthread_mutex_destroy( &mtx );
     85  rtems_test_assert( eno == EBUSY );
     86
     87  sched_yield();
     88
     89  eno = pthread_mutex_destroy( &mtx );
     90  rtems_test_assert( eno == 0 );
     91
     92  eno = pthread_join( th, NULL );
     93  rtems_test_assert( eno == 0 );
     94}
     95
    5296void *POSIX_Init(
    5397  void *argument
     
    66110  TEST_BEGIN();
    67111
     112  test_destroy_locked_mutex();
     113
    68114  /* set the time of day, and print our buffer in multiple ways */
    69115
  • testsuites/psxtests/psx09/system.h

    rbbe654af r48b04fc3  
    3535#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    3636
    37 #define CONFIGURE_MAXIMUM_POSIX_THREADS   1
     37#define CONFIGURE_MAXIMUM_POSIX_THREADS   2
    3838#define CONFIGURE_MAXIMUM_POSIX_KEYS     10
    3939#define CONFIGURE_MAXIMUM_POSIX_MUTEXES  10
Note: See TracChangeset for help on using the changeset viewer.