source: rtems/cpukit/posix/src/condtimedwait.c @ 5cb175bb

4.115
Last change on this file since 5cb175bb was 5cb175bb, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/13 at 19:22:31

cpukit/posix: Doxygen group is POSIXAPI

  • Property mode set to 100644
File size: 1.8 KB
Line 
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/object.h>
26#include <rtems/score/states.h>
27#include <rtems/score/watchdog.h>
28#include <rtems/posix/cond.h>
29#include <rtems/posix/time.h>
30#include <rtems/posix/mutex.h>
31
32/*
33 *  11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105
34 */
35
36int pthread_cond_timedwait(
37  pthread_cond_t        *cond,
38  pthread_mutex_t       *mutex,
39  const struct timespec *abstime
40)
41{
42  Watchdog_Interval                            ticks;
43  bool                                         already_timedout;
44  POSIX_Absolute_timeout_conversion_results_t  status;
45
46  /*
47   *  POSIX requires that blocking calls with timeouts that take
48   *  an absolute timeout must ignore issues with the absolute
49   *  time provided if the operation would otherwise succeed.
50   *  So we check the abstime provided, and hold on to whether it
51   *  is valid or not.  If it isn't correct and in the future,
52   *  then we do a polling operation and convert the UNSATISFIED
53   *  status into the appropriate error.
54   */
55  already_timedout = false;
56  status = _POSIX_Absolute_timeout_to_ticks(abstime, &ticks);
57  if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
58    return EINVAL;
59
60  if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
61       status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
62    already_timedout = true;
63
64  return _POSIX_Condition_variables_Wait_support(
65    cond,
66    mutex,
67    ticks,
68    already_timedout
69  );
70}
Note: See TracBrowser for help on using the repository browser.