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