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.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/posix/condimpl.h> |
---|
22 | #include <rtems/score/todimpl.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 |
---|
26 | */ |
---|
27 | |
---|
28 | int pthread_cond_timedwait( |
---|
29 | pthread_cond_t *cond, |
---|
30 | pthread_mutex_t *mutex, |
---|
31 | const struct timespec *abstime |
---|
32 | ) |
---|
33 | { |
---|
34 | Watchdog_Interval ticks; |
---|
35 | bool already_timedout; |
---|
36 | TOD_Absolute_timeout_conversion_results status; |
---|
37 | |
---|
38 | /* |
---|
39 | * POSIX requires that blocking calls with timeouts that take |
---|
40 | * an absolute timeout must ignore issues with the absolute |
---|
41 | * time provided if the operation would otherwise succeed. |
---|
42 | * So we check the abstime provided, and hold on to whether it |
---|
43 | * is valid or not. If it isn't correct and in the future, |
---|
44 | * then we do a polling operation and convert the UNSATISFIED |
---|
45 | * status into the appropriate error. |
---|
46 | */ |
---|
47 | already_timedout = false; |
---|
48 | status = _TOD_Absolute_timeout_to_ticks(abstime, &ticks); |
---|
49 | if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID ) |
---|
50 | return EINVAL; |
---|
51 | |
---|
52 | if ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST || |
---|
53 | status == TOD_ABSOLUTE_TIMEOUT_IS_NOW ) |
---|
54 | already_timedout = true; |
---|
55 | |
---|
56 | return _POSIX_Condition_variables_Wait_support( |
---|
57 | cond, |
---|
58 | mutex, |
---|
59 | ticks, |
---|
60 | already_timedout |
---|
61 | ); |
---|
62 | } |
---|