Changeset b9f95225 in rtems


Ignore:
Timestamp:
Oct 8, 2014, 8:31:36 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
22cd282
Parents:
dfdad6ab
git-author:
Sebastian Huber <sebastian.huber@…> (10/08/14 08:31:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/08/14 09:26:27)
Message:

posix: Add auto initializaton for rwlock

Files:
11 edited

Legend:

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

    rdfdad6ab rb9f95225  
    9393}
    9494
    95 /**
    96  * @brief Get a RWLock control block.
    97  *
    98  * This function maps RWLock IDs to RWLock control blocks.
    99  * If ID corresponds to a local RWLock, then it returns
    100  * the_RWLock control pointer which maps to ID and location
    101  * is set to OBJECTS_LOCAL.  if the RWLock ID is global and
    102  * resides on a remote node, then location is set to OBJECTS_REMOTE,
    103  * and the_RWLock is undefined.  Otherwise, location is set
    104  * to OBJECTS_ERROR and the_RWLock is undefined.
    105  */
    106 RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Get (
    107   pthread_rwlock_t *RWLock,
     95POSIX_RWLock_Control *_POSIX_RWLock_Get(
     96  pthread_rwlock_t  *rwlock,
    10897  Objects_Locations *location
    109 )
    110 {
    111   return (POSIX_RWLock_Control *) _Objects_Get(
    112       &_POSIX_RWLock_Information,
    113       (Objects_Id) *RWLock,
    114       location
    115   );
    116 }
     98);
    11799
    118100#ifdef __cplusplus
  • cpukit/posix/src/prwlockdestroy.c

    rdfdad6ab rb9f95225  
    4242  Objects_Locations      location;
    4343
    44   if ( !rwlock )
    45     return EINVAL;
    46 
    4744  _Objects_Allocator_lock();
    4845  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
  • cpukit/posix/src/prwlockinit.c

    rdfdad6ab rb9f95225  
    2424#include <errno.h>
    2525
    26 #include <rtems/system.h>
    2726#include <rtems/posix/rwlockimpl.h>
     27#include <rtems/score/apimutex.h>
     28
     29static bool _POSIX_RWLock_Check_id_and_auto_init(
     30  pthread_mutex_t   *rwlock,
     31  Objects_Locations *location
     32)
     33{
     34  if ( rwlock == NULL ) {
     35    *location = OBJECTS_ERROR;
     36
     37    return false;
     38  }
     39
     40  if ( *rwlock == PTHREAD_RWLOCK_INITIALIZER ) {
     41    int eno;
     42
     43    _Once_Lock();
     44
     45    if ( *rwlock == PTHREAD_RWLOCK_INITIALIZER ) {
     46      eno = pthread_rwlock_init( rwlock, NULL );
     47    } else {
     48      eno = 0;
     49    }
     50
     51    _Once_Unlock();
     52
     53    if ( eno != 0 ) {
     54      *location = OBJECTS_ERROR;
     55
     56      return false;
     57    }
     58  }
     59
     60  return true;
     61}
     62
     63POSIX_RWLock_Control *_POSIX_RWLock_Get(
     64  pthread_rwlock_t  *rwlock,
     65  Objects_Locations *location
     66)
     67{
     68  if ( !_POSIX_RWLock_Check_id_and_auto_init( rwlock, location ) ) {
     69    return NULL;
     70  }
     71
     72  return (POSIX_RWLock_Control *) _Objects_Get(
     73    &_POSIX_RWLock_Information,
     74    *rwlock,
     75    location
     76  );
     77}
    2878
    2979/*
  • cpukit/posix/src/prwlockrdlock.c

    rdfdad6ab rb9f95225  
    4242  Thread_Control        *executing;
    4343
    44   if ( !rwlock )
    45     return EINVAL;
    46 
    4744  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
    4845  switch ( location ) {
  • cpukit/posix/src/prwlocktimedrdlock.c

    rdfdad6ab rb9f95225  
    5050  POSIX_Absolute_timeout_conversion_results_t  status;
    5151  Thread_Control                              *executing;
    52 
    53   if ( !rwlock )
    54     return EINVAL;
    5552
    5653  /*
  • cpukit/posix/src/prwlocktimedwrlock.c

    rdfdad6ab rb9f95225  
    5252  POSIX_Absolute_timeout_conversion_results_t  status;
    5353  Thread_Control                              *executing;
    54 
    55   if ( !rwlock )
    56     return EINVAL;
    5754
    5855  /*
  • cpukit/posix/src/prwlocktryrdlock.c

    rdfdad6ab rb9f95225  
    4646  Thread_Control        *executing;
    4747
    48   if ( !rwlock )
    49     return EINVAL;
    50 
    5148  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
    5249  switch ( location ) {
  • cpukit/posix/src/prwlocktrywrlock.c

    rdfdad6ab rb9f95225  
    4646  Thread_Control        *executing;
    4747
    48   if ( !rwlock )
    49     return EINVAL;
    50 
    5148  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
    5249  switch ( location ) {
  • cpukit/posix/src/prwlockunlock.c

    rdfdad6ab rb9f95225  
    4848  CORE_RWLock_Status     status;
    4949
    50   if ( !rwlock )
    51     return EINVAL;
    52 
    5350  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
    5451  switch ( location ) {
  • cpukit/posix/src/prwlockwrlock.c

    rdfdad6ab rb9f95225  
    4848  Thread_Control        *executing;
    4949
    50   if ( !rwlock )
    51     return EINVAL;
    52 
    5350  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
    5451  switch ( location ) {
  • testsuites/psxtests/psxrwlock01/test.c

    rdfdad6ab rb9f95225  
    105105{
    106106  pthread_rwlock_t     rwlock;
     107  pthread_rwlock_t     rwlock2;
    107108  pthread_rwlockattr_t attr;
    108109  int                  status;
     
    154155  rtems_test_assert( status == EINVAL );
    155156
     157  /*************** AUTO INITIALIZATION *****************/
     158
     159  rwlock = PTHREAD_RWLOCK_INITIALIZER;
     160  rwlock2 = PTHREAD_RWLOCK_INITIALIZER;
     161
     162  status = pthread_rwlock_rdlock( &rwlock );
     163  rtems_test_assert( status == 0 );
     164
     165  status = pthread_rwlock_rdlock( &rwlock2 );
     166  rtems_test_assert( status == EINVAL );
     167
     168  status = pthread_rwlock_destroy( &rwlock );
     169  rtems_test_assert( status == 0 );
     170
     171  status = pthread_rwlock_rdlock( &rwlock2 );
     172  rtems_test_assert( status == 0 );
     173
     174  status = pthread_rwlock_destroy( &rwlock );
     175  rtems_test_assert( status == 0 );
     176
     177  rwlock = PTHREAD_RWLOCK_INITIALIZER;
     178  rwlock2 = PTHREAD_RWLOCK_INITIALIZER;
     179
     180  status = pthread_rwlock_rdlock( &rwlock );
     181  rtems_test_assert( status == 0 );
     182
     183  status = pthread_rwlock_destroy( &rwlock2 );
     184  rtems_test_assert( status == EINVAL );
     185
     186  status = pthread_rwlock_destroy( &rwlock );
     187  rtems_test_assert( status == 0 );
     188
     189  status = pthread_rwlock_destroy( &rwlock2 );
     190  rtems_test_assert( status == 0 );
     191  rtems_test_assert( rwlock2 != PTHREAD_RWLOCK_INITIALIZER );
     192
    156193  /*************** ACTUALLY WORK THIS TIME *****************/
    157194  puts( "pthread_rwlockattr_init( &attr ) -- OK" );
Note: See TracChangeset for help on using the changeset viewer.