[047d67a] | 1 | /* |
---|
| 2 | * POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance |
---|
| 3 | * |
---|
[0e87deaa] | 4 | * COPYRIGHT (c) 1989-2007. |
---|
[047d67a] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
| 9 | * http://www.rtems.com/license/LICENSE. |
---|
| 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #if HAVE_CONFIG_H |
---|
| 15 | #include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
| 18 | #include <pthread.h> |
---|
| 19 | #include <errno.h> |
---|
| 20 | |
---|
| 21 | #include <rtems/system.h> |
---|
| 22 | #include <rtems/posix/rwlock.h> |
---|
| 23 | #include <rtems/posix/time.h> |
---|
| 24 | |
---|
| 25 | /* |
---|
| 26 | * pthread_rwlock_timedrdlock |
---|
| 27 | * |
---|
| 28 | * This directive attempts to obtain a read only lock on an rwlock instance. |
---|
| 29 | * |
---|
| 30 | * Input parameters: |
---|
| 31 | * rwlock - pointer to rwlock id |
---|
| 32 | * |
---|
| 33 | * Output parameters: |
---|
| 34 | * 0 - if successful |
---|
| 35 | * error code - if unsuccessful |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | int pthread_rwlock_timedrdlock( |
---|
| 39 | pthread_rwlock_t *rwlock, |
---|
| 40 | const struct timespec *abstime |
---|
| 41 | ) |
---|
| 42 | { |
---|
| 43 | POSIX_RWLock_Control *the_rwlock; |
---|
| 44 | Objects_Locations location; |
---|
| 45 | Watchdog_Interval ticks; |
---|
| 46 | int status; |
---|
| 47 | |
---|
| 48 | if ( !rwlock ) |
---|
| 49 | return EINVAL; |
---|
| 50 | |
---|
| 51 | status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks ); |
---|
[1d56a7a] | 52 | if ( status ) |
---|
[047d67a] | 53 | return status; |
---|
| 54 | |
---|
| 55 | the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); |
---|
| 56 | switch ( location ) { |
---|
| 57 | |
---|
[0e87deaa] | 58 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[047d67a] | 59 | case OBJECTS_REMOTE: |
---|
[0e87deaa] | 60 | #endif |
---|
[047d67a] | 61 | case OBJECTS_ERROR: |
---|
| 62 | return EINVAL; |
---|
| 63 | |
---|
| 64 | case OBJECTS_LOCAL: |
---|
| 65 | |
---|
| 66 | _CORE_RWLock_Obtain_for_reading( |
---|
| 67 | &the_rwlock->RWLock, |
---|
| 68 | *rwlock, |
---|
| 69 | TRUE, // we are willing to wait up to ticks |
---|
| 70 | ticks, |
---|
| 71 | NULL |
---|
| 72 | ); |
---|
| 73 | |
---|
| 74 | _Thread_Enable_dispatch(); |
---|
| 75 | return _POSIX_RWLock_Translate_core_RWLock_return_code( |
---|
| 76 | (CORE_RWLock_Status) _Thread_Executing->Wait.return_code |
---|
| 77 | ); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | return POSIX_BOTTOM_REACHED(); |
---|
| 81 | } |
---|