1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Waiting on a Condition |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <pthread.h> |
---|
22 | #include <errno.h> |
---|
23 | |
---|
24 | #include <rtems/system.h> |
---|
25 | #include <rtems/score/watchdog.h> |
---|
26 | #include <rtems/posix/condimpl.h> |
---|
27 | #include <rtems/posix/time.h> |
---|
28 | #include <rtems/posix/muteximpl.h> |
---|
29 | |
---|
30 | /* |
---|
31 | * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 |
---|
32 | */ |
---|
33 | |
---|
34 | int pthread_cond_timedwait( |
---|
35 | pthread_cond_t *cond, |
---|
36 | pthread_mutex_t *mutex, |
---|
37 | const struct timespec *abstime |
---|
38 | ) |
---|
39 | { |
---|
40 | Watchdog_Interval ticks; |
---|
41 | bool already_timedout; |
---|
42 | POSIX_Absolute_timeout_conversion_results_t status; |
---|
43 | |
---|
44 | /* |
---|
45 | * POSIX requires that blocking calls with timeouts that take |
---|
46 | * an absolute timeout must ignore issues with the absolute |
---|
47 | * time provided if the operation would otherwise succeed. |
---|
48 | * So we check the abstime provided, and hold on to whether it |
---|
49 | * is valid or not. If it isn't correct and in the future, |
---|
50 | * then we do a polling operation and convert the UNSATISFIED |
---|
51 | * status into the appropriate error. |
---|
52 | */ |
---|
53 | already_timedout = false; |
---|
54 | status = _POSIX_Absolute_timeout_to_ticks(abstime, &ticks); |
---|
55 | if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID ) |
---|
56 | return EINVAL; |
---|
57 | |
---|
58 | if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST || |
---|
59 | status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW ) |
---|
60 | already_timedout = true; |
---|
61 | |
---|
62 | return _POSIX_Condition_variables_Wait_support( |
---|
63 | cond, |
---|
64 | mutex, |
---|
65 | ticks, |
---|
66 | already_timedout |
---|
67 | ); |
---|
68 | } |
---|