[799c767] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | #include <stdarg.h> |
---|
| 6 | |
---|
| 7 | #include <errno.h> |
---|
| 8 | #include <fcntl.h> |
---|
| 9 | #include <pthread.h> |
---|
| 10 | #include <semaphore.h> |
---|
| 11 | #include <limits.h> |
---|
| 12 | |
---|
| 13 | #include <rtems/system.h> |
---|
| 14 | #include <rtems/score/object.h> |
---|
| 15 | #include <rtems/posix/semaphore.h> |
---|
| 16 | #include <rtems/posix/time.h> |
---|
| 17 | #include <rtems/posix/seterr.h> |
---|
| 18 | |
---|
| 19 | /*PAGE |
---|
| 20 | * |
---|
| 21 | * _POSIX_Semaphore_Wait_support |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | int _POSIX_Semaphore_Wait_support( |
---|
| 25 | sem_t *sem, |
---|
| 26 | boolean blocking, |
---|
| 27 | Watchdog_Interval timeout |
---|
| 28 | ) |
---|
| 29 | { |
---|
| 30 | register POSIX_Semaphore_Control *the_semaphore; |
---|
| 31 | Objects_Locations location; |
---|
| 32 | |
---|
| 33 | the_semaphore = _POSIX_Semaphore_Get( sem, &location ); |
---|
| 34 | switch ( location ) { |
---|
| 35 | case OBJECTS_ERROR: |
---|
| 36 | set_errno_and_return_minus_one( EINVAL ); |
---|
| 37 | case OBJECTS_REMOTE: |
---|
| 38 | _Thread_Dispatch(); |
---|
| 39 | set_errno_and_return_minus_one( EINVAL ); |
---|
| 40 | case OBJECTS_LOCAL: |
---|
| 41 | _CORE_semaphore_Seize( |
---|
| 42 | &the_semaphore->Semaphore, |
---|
| 43 | the_semaphore->Object.id, |
---|
| 44 | blocking, |
---|
| 45 | timeout |
---|
| 46 | ); |
---|
| 47 | _Thread_Enable_dispatch(); |
---|
[0ca4fc8] | 48 | switch ( _Thread_Executing->Wait.return_code ) { |
---|
| 49 | case CORE_SEMAPHORE_STATUS_SUCCESSFUL: |
---|
[799c767] | 50 | break; |
---|
[0ca4fc8] | 51 | case CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT: |
---|
| 52 | set_errno_and_return_minus_one( EAGAIN ); |
---|
| 53 | case CORE_SEMAPHORE_WAS_DELETED: |
---|
| 54 | set_errno_and_return_minus_one( EAGAIN ); |
---|
| 55 | case CORE_SEMAPHORE_TIMEOUT: |
---|
| 56 | set_errno_and_return_minus_one( ETIMEDOUT ); |
---|
[799c767] | 57 | break; |
---|
[0ca4fc8] | 58 | case CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED: |
---|
| 59 | /* |
---|
| 60 | * This error can not occur since we set the maximum |
---|
| 61 | * count to the largest value the count can hold. |
---|
| 62 | */ |
---|
| 63 | break; |
---|
[799c767] | 64 | } |
---|
| 65 | } |
---|
[0ca4fc8] | 66 | return 0; |
---|
[799c767] | 67 | } |
---|