source: rtems/cpukit/posix/src/posixtimespecabsolutetimeout.c @ 7cd2484

4.115
Last change on this file since 7cd2484 was 7cd2484, checked in by Alexander Krutwig <alexander.krutwig@…>, on 05/12/15 at 12:32:47

timecounter: Use in RTEMS

Replace timestamp implementation with FreeBSD bintime and timecounters.

New test sptests/sptimecounter02.

Update #2271.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Convert Absolute Timeout to Ticks
5 * @ingroup POSIX_TIMETYPES Time Types
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 <stdarg.h>
22
23#include <errno.h>
24#include <fcntl.h>
25#include <pthread.h>
26#include <semaphore.h>
27#include <limits.h>
28
29#include <rtems/posix/semaphoreimpl.h>
30#include <rtems/posix/time.h>
31#include <rtems/score/todimpl.h>
32#include <rtems/seterr.h>
33
34/*
35 *  The abstime is a walltime.  We turn it into an interval.
36 */
37POSIX_Absolute_timeout_conversion_results_t _POSIX_Absolute_timeout_to_ticks(
38  const struct timespec *abstime,
39  Watchdog_Interval     *ticks_out
40)
41{
42  struct timespec current_time;
43  struct timespec difference;
44
45
46  /*
47   *  Make sure there is always a value returned.
48   */
49  *ticks_out = 0;
50
51  /*
52   *  Is the absolute time even valid?
53   */
54  if ( !_Timespec_Is_valid(abstime) )
55    return POSIX_ABSOLUTE_TIMEOUT_INVALID;
56
57  /*
58   *  Is the absolute time in the past?
59   */
60  _TOD_Get_as_timespec( &current_time );
61
62  if ( _Timespec_Less_than( abstime, &current_time ) )
63    return POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST;
64
65  /*
66   *  How long until the requested absolute time?
67   */
68  _Timespec_Subtract( &current_time, abstime, &difference );
69
70  /*
71   *  Internally the SuperCore uses ticks, so convert to them.
72   */
73  *ticks_out = _Timespec_To_ticks( &difference );
74
75  /*
76   *  If the difference was 0, then the future is now.  It is so bright
77   *  we better wear shades.
78   */
79  if ( !*ticks_out )
80    return POSIX_ABSOLUTE_TIMEOUT_IS_NOW;
81
82  /*
83   *  This is the case we were expecting and it took this long to
84   *  get here.
85   */
86  return POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE;
87}
88
Note: See TracBrowser for help on using the repository browser.