Changeset 89fc9345 in rtems


Ignore:
Timestamp:
Sep 21, 2017, 1:42:45 PM (18 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
5222488
Parents:
e67929c
git-author:
Sebastian Huber <sebastian.huber@…> (09/21/17 13:42:45)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/05/17 12:29:02)
Message:

posix: Implement self-contained POSIX rwlocks

POSIX rwlocks are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3115.

Files:
3 deleted
40 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/include/rtems/libcsupport.h

    re67929c r89fc9345  
    115115  uint32_t active_message_queues;
    116116  uint32_t active_mutexes;
    117   uint32_t active_rwlocks;
    118117  uint32_t active_semaphores;
    119118  uint32_t active_threads;
  • cpukit/libcsupport/src/resource_snapshot.c

    re67929c r89fc9345  
    4848  #include <rtems/posix/psignal.h>
    4949  #include <rtems/posix/pthreadimpl.h>
    50   #include <rtems/posix/rwlockimpl.h>
    5150  #include <rtems/posix/semaphoreimpl.h>
    5251  #include <rtems/posix/timerimpl.h>
     
    7372    { OBJECTS_POSIX_API, OBJECTS_POSIX_MESSAGE_QUEUES },
    7473    { OBJECTS_POSIX_API, OBJECTS_POSIX_MUTEXES },
    75     { OBJECTS_POSIX_API, OBJECTS_POSIX_RWLOCKS },
    7674    { OBJECTS_POSIX_API, OBJECTS_POSIX_SEMAPHORES },
    7775    { OBJECTS_POSIX_API, OBJECTS_POSIX_THREADS },
  • cpukit/posix/Makefile.am

    re67929c r89fc9345  
    2323include_rtems_posix_HEADERS += include/rtems/posix/posixapi.h
    2424include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
     25include_rtems_posix_HEADERS += include/rtems/posix/rwlockimpl.h
    2526include_rtems_posix_HEADERS += include/rtems/posix/semaphore.h
    2627include_rtems_posix_HEADERS += include/rtems/posix/semaphoreimpl.h
     
    5152include_rtems_posix_HEADERS += include/rtems/posix/timer.h
    5253include_rtems_posix_HEADERS += include/rtems/posix/timerimpl.h
    53 include_rtems_posix_HEADERS += include/rtems/posix/rwlock.h
    54 include_rtems_posix_HEADERS += include/rtems/posix/rwlockimpl.h
    5554
    5655## src
     
    195194libposix_a_SOURCES += src/semwait.c
    196195
    197 if HAS_PTHREADS
    198 libposix_a_SOURCES += src/sigpending.c \
    199     src/sigqueue.c src/sigsuspend.c src/sigtimedwait.c \
    200     src/sigwait.c src/sigwaitinfo.c src/signal_2.c src/ualarm.c
    201 
    202196## RWLOCK_C_FILES
    203 libposix_a_SOURCES += src/prwlock.c src/prwlockdestroy.c src/prwlockinit.c \
     197libposix_a_SOURCES += src/prwlockdestroy.c src/prwlockinit.c \
    204198    src/prwlockrdlock.c src/prwlocktimedrdlock.c src/prwlocktimedwrlock.c \
    205199    src/prwlocktryrdlock.c src/prwlocktrywrlock.c src/prwlockunlock.c \
     
    207201    src/rwlockattrinit.c src/rwlockattrsetpshared.c
    208202
     203if HAS_PTHREADS
    209204## SEMAPHORE_C_FILES
    210205libposix_a_SOURCES += src/semaphore.c
  • cpukit/posix/include/rtems/posix/config.h

    re67929c r89fc9345  
    100100
    101101  /**
    102    * This field contains the maximum number of POSIX API
    103    * read/write locks which are configured for this application.
    104    */
    105   uint32_t                            maximum_rwlocks;
    106 
    107   /**
    108102   * Maximum configured number of POSIX Shared memory objects.
    109103   */
  • cpukit/posix/include/rtems/posix/rwlockimpl.h

    re67929c r89fc9345  
    2020#define _RTEMS_POSIX_RWLOCKIMPL_H
    2121
    22 #include <rtems/posix/rwlock.h>
    2322#include <rtems/score/corerwlockimpl.h>
    24 #include <rtems/score/objectimpl.h>
    2523
    2624#include <errno.h>
     
    3129#endif
    3230
    33 /**
    34  * The following defines the information control block used to manage
    35  * this class of objects.
    36  */
     31#define POSIX_RWLOCK_MAGIC 0x9621dabdUL
    3732
    38 extern Objects_Information _POSIX_RWLock_Information;
     33typedef struct {
     34  unsigned long flags;
     35  CORE_RWLock_Control RWLock;
     36} POSIX_RWLock_Control;
    3937
    40 /**
    41  * @brief Allocate a RWLock control block.
    42  *
    43  * This function allocates a RWLock control block from
    44  * the inactive chain of free RWLock control blocks.
    45  */
    46 RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Allocate( void )
     38RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Get(
     39  pthread_rwlock_t *rwlock
     40)
    4741{
    48   return (POSIX_RWLock_Control *)
    49     _Objects_Allocate( &_POSIX_RWLock_Information );
     42  return (POSIX_RWLock_Control *) rwlock;
    5043}
    5144
    52 /**
    53  * @brief Free a RWLock control block.
    54  *
    55  * This routine frees a RWLock control block to the
    56  * inactive chain of free RWLock control blocks.
    57  */
    58 RTEMS_INLINE_ROUTINE void _POSIX_RWLock_Free (
    59   POSIX_RWLock_Control *the_RWLock
    60 )
    61 {
    62   _CORE_RWLock_Destroy( &the_RWLock->RWLock );
    63   _Objects_Free( &_POSIX_RWLock_Information, &the_RWLock->Object );
    64 }
     45bool _POSIX_RWLock_Auto_initialization( POSIX_RWLock_Control *the_rwlock );
    6546
    66 POSIX_RWLock_Control *_POSIX_RWLock_Get(
    67   pthread_rwlock_t     *rwlock,
    68   Thread_queue_Context *queue_context
    69 );
     47#define POSIX_RWLOCK_VALIDATE_OBJECT( rw ) \
     48  do { \
     49    if ( ( rw ) == NULL ) { \
     50      return EINVAL; \
     51    } \
     52    if ( ( (uintptr_t) ( rw ) ^ POSIX_RWLOCK_MAGIC ) != ( rw )->flags ) { \
     53      if ( !_POSIX_RWLock_Auto_initialization( rw ) ) { \
     54        return EINVAL; \
     55      } \
     56    } \
     57  } while ( 0 )
    7058
    7159#ifdef __cplusplus
  • cpukit/posix/preinstall.am

    re67929c r89fc9345  
    5151        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
    5252PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
     53
     54$(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h: include/rtems/posix/rwlockimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
     55        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h
     56PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h
    5357
    5458$(PROJECT_INCLUDE)/rtems/posix/semaphore.h: include/rtems/posix/semaphore.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
     
    144148        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
    145149PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
    146 
    147 $(PROJECT_INCLUDE)/rtems/posix/rwlock.h: include/rtems/posix/rwlock.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
    148         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlock.h
    149 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlock.h
    150 
    151 $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h: include/rtems/posix/rwlockimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
    152         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h
    153 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h
    154150endif
    155151if HAS_PTHREADS
  • cpukit/posix/src/prwlockdestroy.c

    re67929c r89fc9345  
    2121
    2222int pthread_rwlock_destroy(
    23   pthread_rwlock_t *rwlock
     23  pthread_rwlock_t *_rwlock
    2424)
    2525{
     
    2727  Thread_queue_Context  queue_context;
    2828
    29   _Objects_Allocator_lock();
    30   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     29  the_rwlock = _POSIX_RWLock_Get( _rwlock );
     30  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    3131
    32   if ( the_rwlock == NULL ) {
    33     _Objects_Allocator_unlock();
    34     return EINVAL;
    35   }
    36 
    37   _CORE_RWLock_Acquire_critical( &the_rwlock->RWLock, &queue_context );
     32  _CORE_RWLock_Acquire( &the_rwlock->RWLock, &queue_context );
    3833
    3934  /*
     
    4136   */
    4237
    43   if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Wait_queue.Queue ) ) {
     38  if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Queue.Queue ) ) {
    4439    _CORE_RWLock_Release( &the_rwlock->RWLock, &queue_context );
    45     _Objects_Allocator_unlock();
    4640    return EBUSY;
    4741  }
     
    5145   */
    5246
    53   _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
     47  the_rwlock->flags = ~the_rwlock->flags;
    5448  _CORE_RWLock_Release( &the_rwlock->RWLock, &queue_context );
    55   _POSIX_RWLock_Free( the_rwlock );
    56   _Objects_Allocator_unlock();
    5749  return 0;
    5850}
  • cpukit/posix/src/prwlockinit.c

    re67929c r89fc9345  
    2424#include <rtems/posix/posixapi.h>
    2525
    26 POSIX_RWLock_Control *_POSIX_RWLock_Get(
    27   pthread_rwlock_t     *rwlock,
    28   Thread_queue_Context *queue_context
    29 )
    30 {
    31   _POSIX_Get_object_body(
    32     POSIX_RWLock_Control,
    33     rwlock,
    34     queue_context,
    35     &_POSIX_RWLock_Information,
    36     PTHREAD_RWLOCK_INITIALIZER,
    37     pthread_rwlock_init
    38   );
    39 }
     26RTEMS_STATIC_ASSERT(
     27  offsetof( POSIX_RWLock_Control, flags )
     28    == offsetof( pthread_rwlock_t, _flags ),
     29  POSIX_RWLOCK_CONTROL_FLAGS
     30);
    4031
    41 /*
    42  *  pthread_rwlock_init
    43  *
    44  *  This directive creates a rwlock.  A rwlock id is returned.
    45  *
    46  *  Input parameters:
    47  *    rwlock          - pointer to rwlock id
    48  *    attr            - rwlock attributes
    49  *
    50  *  Output parameters:
    51  *    rwlock     - rwlock id
    52  *    0          - if successful
    53  *    error code - if unsuccessful
    54  */
     32RTEMS_STATIC_ASSERT(
     33  offsetof( POSIX_RWLock_Control, RWLock.current_state )
     34    == offsetof( pthread_rwlock_t, _current_state ),
     35  POSIX_RWLOCK_CONTROL_CURRENT_STATE
     36);
     37
     38RTEMS_STATIC_ASSERT(
     39  offsetof( POSIX_RWLock_Control, RWLock.number_of_readers )
     40    == offsetof( pthread_rwlock_t, _number_of_readers ),
     41  POSIX_RWLOCK_CONTROL_NUMBER_OF_READERS
     42);
     43
     44RTEMS_STATIC_ASSERT(
     45  offsetof( POSIX_RWLock_Control, RWLock.Queue )
     46    == offsetof( pthread_rwlock_t, _Queue ),
     47  POSIX_RWLOCK_CONTROL_QUEUE
     48);
     49
     50RTEMS_STATIC_ASSERT(
     51  sizeof( POSIX_RWLock_Control ) == sizeof( pthread_rwlock_t ),
     52  POSIX_RWLOCK_CONTROL_SIZE
     53);
    5554
    5655int pthread_rwlock_init(
     
    6160  POSIX_RWLock_Control *the_rwlock;
    6261
    63   /*
    64    *  Error check parameters
    65    */
    66   if ( !rwlock )
     62  the_rwlock = _POSIX_RWLock_Get( rwlock );
     63
     64  if ( the_rwlock == NULL ) {
    6765    return EINVAL;
     66  }
    6867
    6968  if ( attr != NULL ) {
     
    7776  }
    7877
    79   the_rwlock = _POSIX_RWLock_Allocate();
    80 
    81   if ( !the_rwlock ) {
    82     _Objects_Allocator_unlock();
    83     return EAGAIN;
    84   }
    85 
     78  the_rwlock->flags = (uintptr_t) the_rwlock ^ POSIX_RWLOCK_MAGIC;
    8679  _CORE_RWLock_Initialize( &the_rwlock->RWLock );
    87 
    88   _Objects_Open_u32(
    89     &_POSIX_RWLock_Information,
    90     &the_rwlock->Object,
    91     0
    92   );
    93 
    94   *rwlock = the_rwlock->Object.id;
    95 
    96   _Objects_Allocator_unlock();
    9780  return 0;
    9881}
  • cpukit/posix/src/prwlockrdlock.c

    re67929c r89fc9345  
    3030  Status_Control        status;
    3131
    32   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     32  the_rwlock = _POSIX_RWLock_Get( rwlock );
     33  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    3334
    34   if ( the_rwlock == NULL ) {
    35     return EINVAL;
    36   }
    37 
     35  _Thread_queue_Context_initialize( &queue_context );
    3836  _Thread_queue_Context_set_no_timeout( &queue_context );
    3937  status = _CORE_RWLock_Seize_for_reading(
    4038    &the_rwlock->RWLock,
    41     _Thread_Executing,
    4239    true,                 /* we are willing to wait forever */
    4340    &queue_context
  • cpukit/posix/src/prwlocktimedrdlock.c

    re67929c r89fc9345  
    5151  do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
    5252
    53   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     53  the_rwlock = _POSIX_RWLock_Get( rwlock );
     54  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    5455
    55   if ( the_rwlock == NULL ) {
    56     return EINVAL;
    57   }
    58 
     56  _Thread_queue_Context_initialize( &queue_context );
    5957  _Thread_queue_Context_set_relative_timeout( &queue_context, ticks );
    6058  status = _CORE_RWLock_Seize_for_reading(
    6159    &the_rwlock->RWLock,
    62     _Thread_Executing,
    6360    do_wait,
    6461    &queue_context
  • cpukit/posix/src/prwlocktimedwrlock.c

    re67929c r89fc9345  
    5353  do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
    5454
    55   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     55  the_rwlock = _POSIX_RWLock_Get( rwlock );
     56  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    5657
    57   if ( the_rwlock == NULL ) {
    58     return EINVAL;
    59   }
    60 
     58  _Thread_queue_Context_initialize( &queue_context );
    6159  _Thread_queue_Context_set_relative_timeout( &queue_context, ticks );
    6260  status = _CORE_RWLock_Seize_for_writing(
    6361    &the_rwlock->RWLock,
    64     _Thread_Executing,
    6562    do_wait,
    6663    &queue_context
  • cpukit/posix/src/prwlocktryrdlock.c

    re67929c r89fc9345  
    3030  Status_Control        status;
    3131
    32   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     32  the_rwlock = _POSIX_RWLock_Get( rwlock );
     33  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    3334
    34   if ( the_rwlock == NULL ) {
    35     return EINVAL;
    36   }
    37 
     35  _Thread_queue_Context_initialize( &queue_context );
    3836  status = _CORE_RWLock_Seize_for_reading(
    3937    &the_rwlock->RWLock,
    40     _Thread_Executing,
    4138    false,                  /* do not wait for the rwlock */
    4239    &queue_context
  • cpukit/posix/src/prwlocktrywrlock.c

    re67929c r89fc9345  
    3030  Status_Control        status;
    3131
    32   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     32  the_rwlock = _POSIX_RWLock_Get( rwlock );
     33  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    3334
    34   if ( the_rwlock == NULL ) {
    35     return EINVAL;
    36   }
    37 
     35  _Thread_queue_Context_initialize( &queue_context );
    3836  status = _CORE_RWLock_Seize_for_writing(
    3937    &the_rwlock->RWLock,
    40     _Thread_Executing,
    4138    false,                 /* we are not willing to wait */
    4239    &queue_context
  • cpukit/posix/src/prwlockunlock.c

    re67929c r89fc9345  
    2424#include <rtems/posix/posixapi.h>
    2525
     26#include <string.h>
     27
     28bool _POSIX_RWLock_Auto_initialization( POSIX_RWLock_Control *the_rwlock )
     29{
     30  POSIX_RWLock_Control zero;
     31
     32  memset( &zero, 0, sizeof( zero ) );
     33
     34  if ( memcmp( the_rwlock, &zero, sizeof( *the_rwlock ) ) != 0 ) {
     35    return false;
     36  }
     37
     38  the_rwlock->flags = POSIX_RWLOCK_MAGIC;
     39  return true;
     40}
     41
    2642int pthread_rwlock_unlock(
    2743  pthread_rwlock_t  *rwlock
     
    2945{
    3046  POSIX_RWLock_Control *the_rwlock;
    31   Thread_queue_Context  queue_context;
    3247  Status_Control        status;
    3348
    34   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     49  the_rwlock = _POSIX_RWLock_Get( rwlock );
     50  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    3551
    36   if ( the_rwlock == NULL ) {
    37     return EINVAL;
    38   }
    39 
    40   status = _CORE_RWLock_Surrender( &the_rwlock->RWLock, &queue_context );
     52  status = _CORE_RWLock_Surrender( &the_rwlock->RWLock );
    4153  return _POSIX_Get_error( status );
    4254}
  • cpukit/posix/src/prwlockwrlock.c

    re67929c r89fc9345  
    2424#include <rtems/posix/posixapi.h>
    2525
    26 THREAD_QUEUE_OBJECT_ASSERT( POSIX_RWLock_Control, RWLock.Wait_queue );
    27 
    2826int pthread_rwlock_wrlock(
    2927  pthread_rwlock_t  *rwlock
     
    3432  Status_Control        status;
    3533
    36   the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
     34  the_rwlock = _POSIX_RWLock_Get( rwlock );
     35  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
    3736
    38   if ( the_rwlock == NULL ) {
    39     return EINVAL;
    40   }
    41 
     37  _Thread_queue_Context_initialize( &queue_context );
    4238  _Thread_queue_Context_set_no_timeout( &queue_context );
    4339  status = _CORE_RWLock_Seize_for_writing(
    4440    &the_rwlock->RWLock,
    45     _Thread_Executing,
    4641    true,          /* do not timeout -- wait forever */
    4742    &queue_context
  • cpukit/rtems/src/rtemsobjectgetapiclassname.c

    re67929c r89fc9345  
    5454  { "Condition Variable",      OBJECTS_POSIX_CONDITION_VARIABLES, 0},
    5555  { "Timer",                   OBJECTS_POSIX_TIMERS, 0},
    56   { "RWLock",                  OBJECTS_POSIX_RWLOCKS, 0},
    5756  { "Shared Memory",           OBJECTS_POSIX_SHMS, 0},
    5857  { NULL,                      0, 0}
  • cpukit/sapi/include/confdefs.h

    re67929c r89fc9345  
    20822082        rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
    20832083    #endif
    2084     #if !defined(CONFIGURE_MAXIMUM_POSIX_RWLOCKS)
    2085       #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS \
    2086         rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
    2087     #endif
    20882084    #if !defined(CONFIGURE_MAXIMUM_POSIX_SHMS)
    20892085      #define CONFIGURE_MAXIMUM_POSIX_SHMS \
     
    24502446  #include <rtems/posix/psignal.h>
    24512447  #include <rtems/posix/pthread.h>
    2452   #include <rtems/posix/rwlock.h>
    24532448  #include <rtems/posix/semaphore.h>
    24542449  #include <rtems/posix/shm.h>
     
    25662561    _Configure_POSIX_Named_Object_RAM( \
    25672562       _semaphores, sizeof(POSIX_Semaphore_Control) )
    2568 
    2569   /**
    2570    * This configuration parameter specifies the maximum number of
    2571    * POSIX API rwlocks.
    2572    */
    2573   #ifndef CONFIGURE_MAXIMUM_POSIX_RWLOCKS
    2574     #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 0
    2575   #endif
    2576 
    2577   /*
    2578    * This macro is calculated to specify the memory required for
    2579    * POSIX API rwlocks.
    2580    */
    2581   #define _CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) \
    2582     _Configure_Object_RAM(_rwlocks, sizeof(POSIX_RWLock_Control) )
    25832563
    25842564  /**
     
    28232803      _CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( \
    28242804        CONFIGURE_MAXIMUM_POSIX_SEMAPHORES) + \
    2825       _CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( \
    2826         CONFIGURE_MAXIMUM_POSIX_RWLOCKS) + \
    28272805      _CONFIGURE_MEMORY_FOR_POSIX_SHMS( \
    28282806        CONFIGURE_MAXIMUM_POSIX_SHMS) + \
     
    32763254      CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES,
    32773255      CONFIGURE_MAXIMUM_POSIX_SEMAPHORES,
    3278       CONFIGURE_MAXIMUM_POSIX_RWLOCKS,
    32793256      CONFIGURE_MAXIMUM_POSIX_SHMS,
    32803257      CONFIGURE_POSIX_INIT_THREAD_TABLE_SIZE,
     
    34913468    uint32_t POSIX_MESSAGE_QUEUES;
    34923469    uint32_t POSIX_SEMAPHORES;
    3493     uint32_t POSIX_RWLOCKS;
    34943470    uint32_t POSIX_SHMS;
    34953471#endif
     
    35443520      CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES ),
    35453521    _CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( CONFIGURE_MAXIMUM_POSIX_SEMAPHORES ),
    3546     _CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( CONFIGURE_MAXIMUM_POSIX_RWLOCKS ),
    35473522    _CONFIGURE_MEMORY_FOR_POSIX_SHMS( CONFIGURE_MAXIMUM_POSIX_SHMS ),
    35483523    _CONFIGURE_MEMORY_FOR_POSIX_TIMERS( CONFIGURE_MAXIMUM_POSIX_TIMERS ),
     
    36153590       (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES != 0) || \
    36163591       (CONFIGURE_MAXIMUM_POSIX_SEMAPHORES != 0) || \
    3617        (CONFIGURE_MAXIMUM_POSIX_RWLOCKS != 0) || \
    36183592       (CONFIGURE_MAXIMUM_POSIX_SHMS != 0) || \
    36193593      defined(CONFIGURE_POSIX_INIT_THREAD_TABLE))
  • cpukit/sapi/src/posixapi.c

    re67929c r89fc9345  
    2222#include <rtems/posix/posixapi.h>
    2323#include <rtems/posix/barrierimpl.h>
     24#include <rtems/posix/rwlockimpl.h>
    2425#include <rtems/posix/semaphoreimpl.h>
    2526#include <rtems/score/heap.h>
     
    6667  POSIX_BARRIER_MAGIC_4
    6768);
     69RTEMS_STATIC_ASSERT(
     70  POSIX_RWLOCK_MAGIC != HEAP_BEGIN_PROTECTOR_0,
     71  POSIX_RWLOCK_MAGIC_0
     72);
     73RTEMS_STATIC_ASSERT(
     74  POSIX_RWLOCK_MAGIC != HEAP_BEGIN_PROTECTOR_1,
     75  POSIX_RWLOCK_MAGIC_1
     76);
     77RTEMS_STATIC_ASSERT(
     78  POSIX_RWLOCK_MAGIC != HEAP_END_PROTECTOR_0,
     79  POSIX_RWLOCK_MAGIC_2
     80);
     81RTEMS_STATIC_ASSERT(
     82  POSIX_RWLOCK_MAGIC != HEAP_END_PROTECTOR_1,
     83  POSIX_RWLOCK_MAGIC_3
     84);
     85RTEMS_STATIC_ASSERT(
     86  POSIX_RWLOCK_MAGIC != HEAP_FREE_PATTERN,
     87  POSIX_RWLOCK_MAGIC_4
     88);
    6889#endif
    6990
     
    7192  POSIX_SEMAPHORE_MAGIC != POSIX_BARRIER_MAGIC,
    7293  POSIX_SEMAPHORE_MAGIC_5
     94);
     95RTEMS_STATIC_ASSERT(
     96  POSIX_SEMAPHORE_MAGIC != POSIX_RWLOCK_MAGIC,
     97  POSIX_SEMAPHORE_MAGIC_6
     98);
     99RTEMS_STATIC_ASSERT(
     100  POSIX_BARRIER_MAGIC != POSIX_RWLOCK_MAGIC,
     101  POSIX_BARRIER_MAGIC_5
    73102);
    74103
  • cpukit/score/Makefile.am

    re67929c r89fc9345  
    3939include_rtems_score_HEADERS += include/rtems/score/coremutex.h
    4040include_rtems_score_HEADERS += include/rtems/score/coremuteximpl.h
     41include_rtems_score_HEADERS += include/rtems/score/corerwlockimpl.h
    4142include_rtems_score_HEADERS += include/rtems/score/coresem.h
    4243include_rtems_score_HEADERS += include/rtems/score/coresemimpl.h
     
    113114include_rtems_score_HEADERS += include/rtems/score/basedefs.h
    114115
    115 if HAS_PTHREADS
    116 include_rtems_score_HEADERS += include/rtems/score/corerwlock.h
    117 include_rtems_score_HEADERS += include/rtems/score/corerwlockimpl.h
    118 endif
    119 
    120116if HAS_MP
    121117# We only build multiprocessing related files if HAS_MP was defined
     
    190186
    191187## CORE_RWLOCK_C_FILES
    192 if HAS_PTHREADS
    193188libscore_a_SOURCES += src/corerwlock.c src/corerwlockobtainread.c \
    194189    src/corerwlockobtainwrite.c src/corerwlockrelease.c
    195 endif
    196190
    197191## CORE_SEMAPHORE_C_FILES
  • cpukit/score/include/rtems/score/corerwlockimpl.h

    re67929c r89fc9345  
    2020#define _RTEMS_SCORE_CORERWLOCKIMPL_H
    2121
    22 #include <rtems/score/corerwlock.h>
     22#include <rtems/score/percpu.h>
     23#include <rtems/score/status.h>
    2324#include <rtems/score/thread.h>
    2425#include <rtems/score/threadqimpl.h>
    25 #include <rtems/score/status.h>
    2626#include <rtems/score/watchdog.h>
    2727
     
    5050
    5151/**
     52 *  RWLock State.
     53 */
     54typedef enum {
     55  /** This indicates the the RWLock is not currently locked.
     56   */
     57  CORE_RWLOCK_UNLOCKED,
     58  /** This indicates the the RWLock is currently locked for reading.
     59   */
     60  CORE_RWLOCK_LOCKED_FOR_READING,
     61  /** This indicates the the RWLock is currently locked for reading.
     62   */
     63  CORE_RWLOCK_LOCKED_FOR_WRITING
     64}   CORE_RWLock_States;
     65
     66/**
     67 *  The following defines the control block used to manage each
     68 *  RWLock.
     69 */
     70typedef struct {
     71  /** This field is the Waiting Queue used to manage the set of tasks
     72   *  which are blocked waiting for the RWLock to be released.
     73   */
     74  Thread_queue_Syslock_queue Queue;
     75
     76  /** This element is the current state of the RWLock.
     77   */
     78  CORE_RWLock_States current_state;
     79
     80  /** This element contains the current number of thread waiting for this
     81   *  RWLock to be released. */
     82  unsigned int number_of_readers;
     83}   CORE_RWLock_Control;
     84
     85/**
    5286 *  @brief Initialize a RWlock.
    5387 *
     
    6498)
    6599{
    66   _Thread_queue_Destroy( &the_rwlock->Wait_queue );
     100  (void) the_rwlock;
    67101}
    68102
    69 RTEMS_INLINE_ROUTINE void _CORE_RWLock_Acquire_critical(
     103RTEMS_INLINE_ROUTINE Thread_Control *_CORE_RWLock_Acquire(
    70104  CORE_RWLock_Control  *the_rwlock,
    71105  Thread_queue_Context *queue_context
    72106)
    73107{
    74   _Thread_queue_Acquire_critical( &the_rwlock->Wait_queue, queue_context );
     108  ISR_Level       level;
     109  Thread_Control *executing;
     110
     111  _Thread_queue_Context_ISR_disable( queue_context, level );
     112  _Thread_queue_Context_set_ISR_level( queue_context, level );
     113  executing = _Thread_Executing;
     114  _Thread_queue_Queue_acquire_critical(
     115    &the_rwlock->Queue.Queue,
     116    &executing->Potpourri_stats,
     117    &queue_context->Lock_context.Lock_context
     118  );
     119
     120  return executing;
    75121}
    76122
     
    80126)
    81127{
    82   _Thread_queue_Release( &the_rwlock->Wait_queue, queue_context );
     128  _Thread_queue_Queue_release(
     129    &the_rwlock->Queue.Queue,
     130    &queue_context->Lock_context.Lock_context
     131  );
    83132}
    84133
     
    94143Status_Control _CORE_RWLock_Seize_for_reading(
    95144  CORE_RWLock_Control  *the_rwlock,
    96   Thread_Control       *executing,
    97145  bool                  wait,
    98146  Thread_queue_Context *queue_context
     
    109157Status_Control _CORE_RWLock_Seize_for_writing(
    110158  CORE_RWLock_Control  *the_rwlock,
    111   Thread_Control       *executing,
    112159  bool                  wait,
    113160  Thread_queue_Context *queue_context
     
    124171 *  @retval Status is returned to indicate successful or failure.
    125172 */
    126 Status_Control _CORE_RWLock_Surrender(
    127   CORE_RWLock_Control  *the_rwlock,
    128   Thread_queue_Context *queue_context
    129 );
     173Status_Control _CORE_RWLock_Surrender( CORE_RWLock_Control *the_rwlock );
    130174
    131175/** @} */
  • cpukit/score/include/rtems/score/objectimpl.h

    re67929c r89fc9345  
    9292  OBJECTS_POSIX_CONDITION_VARIABLES = 8,
    9393  OBJECTS_POSIX_TIMERS              = 9,
    94   OBJECTS_POSIX_RWLOCKS             = 11,
    9594  OBJECTS_POSIX_SHMS                = 12
    9695} Objects_POSIX_API;
  • cpukit/score/include/rtems/sysinit.h

    re67929c r89fc9345  
    5353#define RTEMS_SYSINIT_POSIX_SEMAPHORE            000365
    5454#define RTEMS_SYSINIT_POSIX_TIMER                000366
    55 #define RTEMS_SYSINIT_POSIX_RWLOCK               000368
    5655#define RTEMS_SYSINIT_POSIX_SHM                  000369
    5756#define RTEMS_SYSINIT_POSIX_KEYS                 00036a
  • cpukit/score/preinstall.am

    re67929c r89fc9345  
    121121PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremuteximpl.h
    122122
     123$(PROJECT_INCLUDE)/rtems/score/corerwlockimpl.h: include/rtems/score/corerwlockimpl.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
     124        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlockimpl.h
     125PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlockimpl.h
     126
    123127$(PROJECT_INCLUDE)/rtems/score/coresem.h: include/rtems/score/coresem.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    124128        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coresem.h
     
    413417PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/basedefs.h
    414418
    415 if HAS_PTHREADS
    416 $(PROJECT_INCLUDE)/rtems/score/corerwlock.h: include/rtems/score/corerwlock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    417         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlock.h
    418 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlock.h
    419 
    420 $(PROJECT_INCLUDE)/rtems/score/corerwlockimpl.h: include/rtems/score/corerwlockimpl.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    421         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlockimpl.h
    422 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlockimpl.h
    423 endif
    424419if HAS_MP
    425420$(PROJECT_INCLUDE)/rtems/score/mpci.h: include/rtems/score/mpci.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
  • cpukit/score/src/corerwlock.c

    re67929c r89fc9345  
    2828  the_rwlock->number_of_readers = 0;
    2929  the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
    30 
    31   _Thread_queue_Object_initialize( &the_rwlock->Wait_queue );
     30  _Thread_queue_Queue_initialize( &the_rwlock->Queue.Queue, NULL );
    3231}
  • cpukit/score/src/corerwlockobtainread.c

    re67929c r89fc9345  
    2727Status_Control _CORE_RWLock_Seize_for_reading(
    2828  CORE_RWLock_Control  *the_rwlock,
    29   Thread_Control       *executing,
    3029  bool                  wait,
    3130  Thread_queue_Context *queue_context
    3231)
    3332{
     33  Thread_Control *executing;
     34
    3435  /*
    3536   *  If unlocked, then OK to read.
     
    3839   */
    3940
    40   _CORE_RWLock_Acquire_critical( the_rwlock, queue_context );
     41  executing = _CORE_RWLock_Acquire( the_rwlock, queue_context );
    4142
    4243  switch ( the_rwlock->current_state ) {
     
    4748      return STATUS_SUCCESSFUL;
    4849
    49     case CORE_RWLOCK_LOCKED_FOR_READING: {
    50       Thread_Control *waiter;
    51       waiter = _Thread_queue_First_locked(
    52         &the_rwlock->Wait_queue,
    53         CORE_RWLOCK_TQ_OPERATIONS
    54       );
    55       if ( !waiter ) {
     50    case CORE_RWLOCK_LOCKED_FOR_READING:
     51      if ( _Thread_queue_Is_empty( &the_rwlock->Queue.Queue ) ) {
    5652        the_rwlock->number_of_readers += 1;
    5753        _CORE_RWLock_Release( the_rwlock, queue_context );
     
    5955      }
    6056      break;
    61     }
    6257    case CORE_RWLOCK_LOCKED_FOR_WRITING:
    6358      break;
     
    8580  _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
    8681  _Thread_queue_Enqueue(
    87      &the_rwlock->Wait_queue.Queue,
     82     &the_rwlock->Queue.Queue,
    8883     CORE_RWLOCK_TQ_OPERATIONS,
    8984     executing,
  • cpukit/score/src/corerwlockobtainwrite.c

    re67929c r89fc9345  
    2727Status_Control _CORE_RWLock_Seize_for_writing(
    2828  CORE_RWLock_Control  *the_rwlock,
    29   Thread_Control       *executing,
    3029  bool                  wait,
    3130  Thread_queue_Context *queue_context
    3231)
    3332{
     33  Thread_Control *executing;
     34
    3435  /*
    3536   *  If unlocked, then OK to read.
     
    3940   */
    4041
    41   _CORE_RWLock_Acquire_critical( the_rwlock, queue_context );
     42  executing = _CORE_RWLock_Acquire( the_rwlock, queue_context );
    4243
    4344  switch ( the_rwlock->current_state ) {
     
    7374  _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
    7475  _Thread_queue_Enqueue(
    75      &the_rwlock->Wait_queue.Queue,
     76     &the_rwlock->Queue.Queue,
    7677     CORE_RWLOCK_TQ_OPERATIONS,
    7778     executing,
  • cpukit/score/src/corerwlockrelease.c

    re67929c r89fc9345  
    4646    queue,
    4747    CORE_RWLock_Control,
    48     Wait_queue.Queue
     48    Queue.Queue
    4949  );
    5050
     
    7474}
    7575
    76 Status_Control _CORE_RWLock_Surrender(
    77   CORE_RWLock_Control  *the_rwlock,
    78   Thread_queue_Context *queue_context
    79 )
     76Status_Control _CORE_RWLock_Surrender( CORE_RWLock_Control *the_rwlock )
    8077{
     78  Thread_queue_Context queue_context;
     79
    8180  /*
    8281   *  If unlocked, then OK to read.
     
    8685   */
    8786
    88   _CORE_RWLock_Acquire_critical( the_rwlock, queue_context );
     87  _Thread_queue_Context_initialize( &queue_context );
     88  _CORE_RWLock_Acquire( the_rwlock, &queue_context );
    8989
    9090  if ( the_rwlock->current_state == CORE_RWLOCK_UNLOCKED){
    9191    /* This is an error at the caller site */
    92     _CORE_RWLock_Release( the_rwlock, queue_context );
     92    _CORE_RWLock_Release( the_rwlock, &queue_context );
    9393    return STATUS_SUCCESSFUL;
    9494  }
     
    9999    if ( the_rwlock->number_of_readers != 0 ) {
    100100      /* must be unlocked again */
    101       _CORE_RWLock_Release( the_rwlock, queue_context );
     101      _CORE_RWLock_Release( the_rwlock, &queue_context );
    102102      return STATUS_SUCCESSFUL;
    103103    }
     
    117117
    118118  _Thread_queue_Flush_critical(
    119     &the_rwlock->Wait_queue.Queue,
     119    &the_rwlock->Queue.Queue,
    120120    CORE_RWLOCK_TQ_OPERATIONS,
    121121    _CORE_RWLock_Flush_filter,
    122     queue_context
     122    &queue_context
    123123  );
    124124  return STATUS_SUCCESSFUL;
  • testsuites/psxtests/psxconfig01/init.c

    re67929c r89fc9345  
    6565#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 19
    6666#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 7
    67 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 31
    6867#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 41
    6968#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
     
    475474#endif
    476475
    477 #ifdef CONFIGURE_MAXIMUM_POSIX_RWLOCKS
    478   for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_RWLOCKS; ++i) {
    479     pthread_rwlock_t rwlock;
    480     eno = pthread_rwlock_init(&rwlock, NULL);
    481     rtems_test_assert(eno == 0);
    482   }
    483   rtems_resource_snapshot_take(&snapshot);
    484   rtems_test_assert(
    485     snapshot.posix_api.active_rwlocks == CONFIGURE_MAXIMUM_POSIX_RWLOCKS
    486   );
    487 #endif
    488 
    489476#ifdef CONFIGURE_MAXIMUM_POSIX_SEMAPHORES
    490477  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; ++i) {
  • testsuites/psxtests/psxrwlock01/main.c

    re67929c r89fc9345  
    4040
    4141#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
    42 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 1
    4342
    4443#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
  • testsuites/psxtests/psxrwlock01/psxrwlock01.scn

    re67929c r89fc9345  
    1 *** POSIX RWLOCK TEST 01 ***
     1*** BEGIN OF TEST PSXRWLOCK 1 ***
    22pthread_rwlockattr_init( NULL ) -- EINVAL
    33pthread_rwlockattr_setpshared( NULL, private ) -- EINVAL
     
    3838pthread_rwlockattr_init( &attr ) -- OK
    3939pthread_rwlock_init( &rwlock, &attr ) -- OK
    40 pthread_rwlock_init( &rwlock, &attr ) -- EAGAIN
    4140pthread_rwlock_destroy( &rwlock ) -- OK
    4241pthread_rwlock_init( &rwlock, NULL ) -- OK
     
    9594pthread_rwlock_unlock ( &rwlock ) -- OK
    9695pthread_rwlock_unlock ( &rwlock ) -- OK
    97 *** END OF POSIX RWLOCK TEST 01 ***
     96*** END OF TEST PSXRWLOCK 1 ***
  • testsuites/psxtests/psxrwlock01/test.c

    re67929c r89fc9345  
    9191}
    9292
    93 static void test_pshared_init(void)
     93static void test_rwlock_pshared_init(void)
    9494{
    9595  pthread_rwlock_t rwlock;
     
    125125  eno = pthread_rwlockattr_destroy(&attr);
    126126  rtems_test_assert(eno == 0);
     127}
     128
     129static void test_rwlock_null( void )
     130{
     131  struct timespec to;
     132  int eno;
     133
     134  eno = pthread_rwlock_destroy( NULL );
     135  rtems_test_assert( eno == EINVAL );
     136
     137  eno = pthread_rwlock_init( NULL, NULL );
     138  rtems_test_assert( eno == EINVAL );
     139
     140  eno = pthread_rwlock_rdlock( NULL );
     141  rtems_test_assert( eno == EINVAL );
     142
     143  to.tv_sec = 1;
     144  to.tv_nsec = 1;
     145  eno = pthread_rwlock_timedrdlock( NULL, &to );
     146  rtems_test_assert( eno == EINVAL );
     147
     148  to.tv_sec = 1;
     149  to.tv_nsec = 1;
     150  eno = pthread_rwlock_timedwrlock( NULL, &to );
     151  rtems_test_assert( eno == EINVAL );
     152
     153  eno = pthread_rwlock_tryrdlock( NULL );
     154  rtems_test_assert( eno == EINVAL );
     155
     156  eno = pthread_rwlock_trywrlock( NULL );
     157  rtems_test_assert( eno == EINVAL );
     158
     159  eno = pthread_rwlock_unlock( NULL );
     160  rtems_test_assert( eno == EINVAL );
     161
     162  eno = pthread_rwlock_wrlock( NULL );
     163  rtems_test_assert( eno == EINVAL );
     164}
     165
     166static void test_rwlock_not_initialized( void )
     167{
     168  pthread_rwlock_t rw;
     169  struct timespec to;
     170  int eno;
     171
     172  memset( &rw, 0xff, sizeof( rw ) );
     173
     174  eno = pthread_rwlock_destroy( &rw );
     175  rtems_test_assert( eno == EINVAL );
     176
     177  eno = pthread_rwlock_rdlock( &rw );
     178  rtems_test_assert( eno == EINVAL );
     179
     180  to.tv_sec = 1;
     181  to.tv_nsec = 1;
     182  eno = pthread_rwlock_timedrdlock( &rw, &to );
     183  rtems_test_assert( eno == EINVAL );
     184
     185  to.tv_sec = 1;
     186  to.tv_nsec = 1;
     187  eno = pthread_rwlock_timedwrlock( &rw, &to );
     188  rtems_test_assert( eno == EINVAL );
     189
     190  eno = pthread_rwlock_tryrdlock( &rw );
     191  rtems_test_assert( eno == EINVAL );
     192
     193  eno = pthread_rwlock_trywrlock( &rw );
     194  rtems_test_assert( eno == EINVAL );
     195
     196  eno = pthread_rwlock_unlock( &rw );
     197  rtems_test_assert( eno == EINVAL );
     198
     199  eno = pthread_rwlock_wrlock( &rw );
     200  rtems_test_assert( eno == EINVAL );
     201}
     202
     203static void test_rwlock_invalid_copy( void )
     204{
     205  pthread_rwlock_t rw;
     206  pthread_rwlock_t rw2;
     207  struct timespec to;
     208  int eno;
     209
     210  eno = pthread_rwlock_init( &rw, NULL );
     211  rtems_test_assert( eno == 0 );
     212
     213  memcpy( &rw2, &rw, sizeof( rw2 ) );
     214
     215  eno = pthread_rwlock_destroy( &rw2 );
     216  rtems_test_assert( eno == EINVAL );
     217
     218  eno = pthread_rwlock_rdlock( &rw2 );
     219  rtems_test_assert( eno == EINVAL );
     220
     221  to.tv_sec = 1;
     222  to.tv_nsec = 1;
     223  eno = pthread_rwlock_timedrdlock( &rw2, &to );
     224  rtems_test_assert( eno == EINVAL );
     225
     226  to.tv_sec = 1;
     227  to.tv_nsec = 1;
     228  eno = pthread_rwlock_timedwrlock( &rw2, &to );
     229  rtems_test_assert( eno == EINVAL );
     230
     231  eno = pthread_rwlock_tryrdlock( &rw2 );
     232  rtems_test_assert( eno == EINVAL );
     233
     234  eno = pthread_rwlock_trywrlock( &rw2 );
     235  rtems_test_assert( eno == EINVAL );
     236
     237  eno = pthread_rwlock_unlock( &rw2 );
     238  rtems_test_assert( eno == EINVAL );
     239
     240  eno = pthread_rwlock_wrlock( &rw2 );
     241  rtems_test_assert( eno == EINVAL );
     242
     243  eno = pthread_rwlock_destroy( &rw );
     244  rtems_test_assert( eno == 0 );
     245}
     246
     247static void test_rwlock_auto_initialization( void )
     248{
     249  struct timespec to;
     250  int eno;
     251
     252  {
     253    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     254
     255    eno = pthread_rwlock_destroy( &rw );
     256    rtems_test_assert( eno == 0 );
     257
     258    eno = pthread_rwlock_destroy( &rw );
     259    rtems_test_assert( eno == EINVAL );
     260  }
     261
     262  {
     263    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     264
     265    eno = pthread_rwlock_rdlock( &rw );
     266    rtems_test_assert( eno == 0 );
     267  }
     268
     269  {
     270    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     271
     272    to.tv_sec = 1;
     273    to.tv_nsec = 1;
     274    eno = pthread_rwlock_timedrdlock( &rw, &to );
     275    rtems_test_assert( eno == 0 );
     276  }
     277
     278  {
     279    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     280
     281    to.tv_sec = 1;
     282    to.tv_nsec = 1;
     283    eno = pthread_rwlock_timedwrlock( &rw, &to );
     284    rtems_test_assert( eno == 0 );
     285  }
     286
     287  {
     288    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     289
     290    eno = pthread_rwlock_tryrdlock( &rw );
     291    rtems_test_assert( eno == 0 );
     292  }
     293
     294  {
     295    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     296
     297    eno = pthread_rwlock_trywrlock( &rw );
     298    rtems_test_assert( eno == 0 );
     299  }
     300
     301  {
     302    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     303
     304    eno = pthread_rwlock_unlock( &rw );
     305    rtems_test_assert( eno == 0 );
     306  }
     307
     308  {
     309    static pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
     310
     311    eno = pthread_rwlock_wrlock( &rw );
     312    rtems_test_assert( eno == 0 );
     313  }
    127314}
    128315
     
    141328{
    142329  pthread_rwlock_t     rwlock;
    143   pthread_rwlock_t     rwlock2;
    144330  pthread_rwlockattr_t attr;
    145331  int                  status;
     
    150336  TEST_BEGIN();
    151337
    152   test_pshared_init();
     338  test_rwlock_pshared_init();
     339  test_rwlock_null();
     340  test_rwlock_not_initialized();
     341  test_rwlock_invalid_copy();
     342  test_rwlock_auto_initialization();
    153343
    154344  /*************** NULL POINTER CHECKS *****************/
     
    193383  rtems_test_assert( status == EINVAL );
    194384
    195   /*************** AUTO INITIALIZATION *****************/
    196 
    197   rwlock = PTHREAD_RWLOCK_INITIALIZER;
    198   rwlock2 = PTHREAD_RWLOCK_INITIALIZER;
    199 
    200   status = pthread_rwlock_rdlock( &rwlock );
    201   rtems_test_assert( status == 0 );
    202 
    203   status = pthread_rwlock_rdlock( &rwlock2 );
    204   rtems_test_assert( status == EINVAL );
    205 
    206   status = pthread_rwlock_destroy( &rwlock );
    207   rtems_test_assert( status == 0 );
    208 
    209   status = pthread_rwlock_rdlock( &rwlock2 );
    210   rtems_test_assert( status == 0 );
    211 
    212   status = pthread_rwlock_destroy( &rwlock );
    213   rtems_test_assert( status == 0 );
    214 
    215   rwlock = PTHREAD_RWLOCK_INITIALIZER;
    216   rwlock2 = PTHREAD_RWLOCK_INITIALIZER;
    217 
    218   status = pthread_rwlock_rdlock( &rwlock );
    219   rtems_test_assert( status == 0 );
    220 
    221   status = pthread_rwlock_destroy( &rwlock2 );
    222   rtems_test_assert( status == EINVAL );
    223 
    224   status = pthread_rwlock_destroy( &rwlock );
    225   rtems_test_assert( status == 0 );
    226 
    227   status = pthread_rwlock_destroy( &rwlock2 );
    228   rtems_test_assert( status == 0 );
    229   rtems_test_assert( rwlock2 != PTHREAD_RWLOCK_INITIALIZER );
    230 
    231385  /*************** ACTUALLY WORK THIS TIME *****************/
    232386  puts( "pthread_rwlockattr_init( &attr ) -- OK" );
     
    310464
    311465  /*************** BAD ID CHECK *****************/
    312   rwlock = 1;
    313466  /* make a valid abstime */
    314467  puts( "clock_gettime(CLOCK_REALTIME, &abstime) -- OK" );
     
    318471
    319472  puts( "pthread_rwlock_destroy(BadId) -- EINVAL" );
    320   status = pthread_rwlock_destroy(&rwlock);
     473  status = pthread_rwlock_destroy(NULL);
    321474  rtems_test_assert( status == EINVAL );
    322475
    323476  puts( "pthread_rwlock_rdlock(BadId) -- EINVAL" );
    324   status = pthread_rwlock_rdlock(&rwlock);
     477  status = pthread_rwlock_rdlock(NULL);
    325478  rtems_test_assert( status == EINVAL );
    326479
    327480  puts( "pthread_rwlock_timedrdlock(BadId, &abstime) -- EINVAL" );
    328   status = pthread_rwlock_timedrdlock( &rwlock, &abstime);
     481  status = pthread_rwlock_timedrdlock( NULL, &abstime);
    329482  rtems_test_assert( status == EINVAL );
    330483
    331484  puts( "pthread_rwlock_tryrdlock(BadId) -- EINVAL" );
    332   status = pthread_rwlock_tryrdlock(&rwlock);
     485  status = pthread_rwlock_tryrdlock(NULL);
    333486  rtems_test_assert( status == EINVAL );
    334487
    335488  puts( "pthread_rwlock_wrlock(BadId) -- EINVAL" );
    336   status = pthread_rwlock_wrlock(&rwlock);
     489  status = pthread_rwlock_wrlock(NULL);
    337490  rtems_test_assert( status == EINVAL );
    338491
    339492  puts( "pthread_rwlock_timedwrlock(BadId, &abstime) -- EINVAL" );
    340   status = pthread_rwlock_timedwrlock( &rwlock, &abstime );
     493  status = pthread_rwlock_timedwrlock( NULL, &abstime );
    341494  rtems_test_assert( status == EINVAL );
    342495
    343496  puts( "pthread_rwlock_trywrlock(BadId) -- EINVAL" );
    344   status = pthread_rwlock_trywrlock(&rwlock);
     497  status = pthread_rwlock_trywrlock(NULL);
    345498  rtems_test_assert( status == EINVAL );
    346499
    347500  puts( "pthread_rwlock_unlock(BadId) -- EINVAL" );
    348   status = pthread_rwlock_unlock(&rwlock);
     501  status = pthread_rwlock_unlock(NULL);
    349502  rtems_test_assert( status == EINVAL );
    350503
     
    369522  status = pthread_rwlock_init( &rwlock, &attr );
    370523  rtems_test_assert( status == 0 );
    371   rtems_test_assert( rwlock != 0 );
    372 
    373   puts( "pthread_rwlock_init( &rwlock, &attr ) -- EAGAIN" );
    374   status = pthread_rwlock_init( &rwlock, &attr );
    375   rtems_test_assert( status == EAGAIN );
    376524
    377525  puts( "pthread_rwlock_destroy( &rwlock ) -- OK" );
     
    550698  status = pthread_rwlock_init( &rwlock, NULL );
    551699  rtems_test_assert( status == 0 );
    552   rtems_test_assert( rwlock != 0 );
    553700
    554701  puts( "pthread_rwlock_unlock ( &rwlock ) -- OK" );
  • testsuites/psxtmtests/psxtmrwlock01/init.c

    re67929c r89fc9345  
    272272
    273273#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
    274 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    275274#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    276275
  • testsuites/psxtmtests/psxtmrwlock02/init.c

    re67929c r89fc9345  
    127127
    128128#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
    129 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    130129#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    131130
  • testsuites/psxtmtests/psxtmrwlock03/init.c

    re67929c r89fc9345  
    140140
    141141#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
    142 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    143142#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    144143
  • testsuites/psxtmtests/psxtmrwlock04/init.c

    re67929c r89fc9345  
    128128
    129129#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
    130 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    131130#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    132131
  • testsuites/psxtmtests/psxtmrwlock05/init.c

    re67929c r89fc9345  
    140140
    141141#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
    142 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    143142#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    144143
  • testsuites/psxtmtests/psxtmrwlock06/init.c

    re67929c r89fc9345  
    102102
    103103#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
    104 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    105104#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    106105
  • testsuites/psxtmtests/psxtmrwlock07/init.c

    re67929c r89fc9345  
    159159
    160160#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
    161 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
    162161#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    163162
  • testsuites/sptests/spsysinit01/init.c

    re67929c r89fc9345  
    115115  POSIX_TIMER_PRE,
    116116  POSIX_TIMER_POST,
    117   POSIX_RWLOCK_PRE,
    118   POSIX_RWLOCK_POST,
    119117  POSIX_SHM_PRE,
    120118  POSIX_SHM_POST,
     
    504502}
    505503
    506 FIRST(RTEMS_SYSINIT_POSIX_RWLOCK)
    507 {
    508   assert(_POSIX_RWLock_Information.maximum == 0);
    509   next_step(POSIX_RWLOCK_PRE);
    510 }
    511 
    512 LAST(RTEMS_SYSINIT_POSIX_RWLOCK)
    513 {
    514   assert(_POSIX_RWLock_Information.maximum != 0);
    515   next_step(POSIX_RWLOCK_POST);
    516 }
    517 
    518504FIRST(RTEMS_SYSINIT_POSIX_SHM)
    519505{
     
    750736#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 1
    751737
    752 #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 1
    753 
    754738#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
    755739
  • testsuites/sptests/spthreadq01/init.c

    re67929c r89fc9345  
    4343  pthread_mutex_t pmtx;
    4444  pthread_cond_t pcv;
    45   pthread_rwlock_t prw;
    4645  mqd_t pmq;
    4746#endif
     
    138137
    139138  eno = pthread_mutex_unlock(&ctx->pmtx);
    140   rtems_test_assert(eno == 0);
    141 
    142   eno = pthread_rwlock_wrlock(&ctx->prw);
    143   rtems_test_assert(eno == 0);
    144 
    145   wake_up_master(ctx);
    146   rtems_test_assert(get_wait_id(ctx) == ctx->prw);
    147 
    148   eno = pthread_rwlock_unlock(&ctx->prw);
    149139  rtems_test_assert(eno == 0);
    150140
     
    218208
    219209  eno = pthread_cond_init(&ctx->pcv, NULL);
    220   rtems_test_assert(eno == 0);
    221 
    222   eno = pthread_rwlock_init(&ctx->prw, NULL);
    223210  rtems_test_assert(eno == 0);
    224211
     
    314301  wait_for_worker(ctx);
    315302
    316   eno = pthread_rwlock_wrlock(&ctx->prw);
    317   rtems_test_assert(eno == 0);
    318 
    319   wait_for_worker(ctx);
    320 
    321303  buf[0] = 'y';
    322304  prio = 1;
     
    363345  #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1
    364346  #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 1
    365   #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 1
    366347  #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1
    367348  #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
Note: See TracChangeset for help on using the changeset viewer.