source: rtems/cpukit/posix/src/posixtimespecabsolutetimeout.c @ ba16717

4.104.114.84.95
Last change on this file since ba16717 was ba16717, checked in by Joel Sherrill <joel.sherrill@…>, on 11/15/06 at 15:34:45

2006-11-15 Joel Sherrill <joel.sherrill@…>

  • posix/Makefile.am: Add file missed in previous commit.
  • posix/src/posixtimespecabsolutetimeout.c: New file.
  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 *  Convert abstime timeout to ticks
3 *
4 *  $Id$
5 */
6
7#if HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <stdarg.h>
12
13#include <errno.h>
14#include <fcntl.h>
15#include <pthread.h>
16#include <semaphore.h>
17#include <limits.h>
18
19#include <rtems/system.h>
20#include <rtems/score/object.h>
21#include <rtems/posix/semaphore.h>
22#include <rtems/posix/time.h>
23#include <rtems/seterr.h>
24
25/*
26 *  The abstime is a walltime.  We turn it into an interval.
27 */
28int _POSIX_Absolute_timeout_to_ticks(
29  const struct timespec *abstime,
30  Watchdog_Interval     *ticks_out
31)
32{
33  struct timespec   current_time;
34  struct timespec   difference;
35
36  if ( !abstime )
37    return EINVAL;
38
39  /*
40   *  Error check the absolute time to timeout
41   */
42#if 0
43   /* they are unsigned so this is impossible */
44  if ( abstime->tv_sec < 0 || abstime->tv_nsec < 0 )
45    return EINVAL;
46#endif
47
48  if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
49    return EINVAL;
50 
51  (void) clock_gettime( CLOCK_REALTIME, &current_time );
52
53  /*
54   *  Make sure the abstime is in the future
55   */
56  if ( abstime->tv_sec < current_time.tv_sec )
57    return EINVAL;
58
59  if ( (abstime->tv_sec == current_time.tv_sec) &&
60       (abstime->tv_nsec <= current_time.tv_nsec) )
61    return EINVAL;
62
63  _POSIX_Timespec_subtract( &current_time, abstime, &difference );
64
65  *ticks_out = _POSIX_Timespec_to_interval( &difference );
66
67  return 0;
68}
69
Note: See TracBrowser for help on using the repository browser.