From ba16717a62bd93431b6523a6b24beddcb232dca7 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 15 Nov 2006 15:34:45 +0000 Subject: 2006-11-15 Joel Sherrill * posix/Makefile.am: Add file missed in previous commit. * posix/src/posixtimespecabsolutetimeout.c: New file. --- cpukit/ChangeLog | 5 ++ cpukit/posix/Makefile.am | 7 +-- cpukit/posix/src/posixtimespecabsolutetimeout.c | 69 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 cpukit/posix/src/posixtimespecabsolutetimeout.c (limited to 'cpukit') diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 1b59a79250..afc4011568 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,8 @@ +2006-11-15 Joel Sherrill + + * posix/Makefile.am: Add file missed in previous commit. + * posix/src/posixtimespecabsolutetimeout.c: New file. + 2006-11-15 Ralf Corsépius * configure.ac: Remove RTEMS_AMPOLISH3. diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am index 49f86640c7..52522befd8 100644 --- a/cpukit/posix/Makefile.am +++ b/cpukit/posix/Makefile.am @@ -146,9 +146,10 @@ libposix_a_SOURCES += src/pspin.c src/pspindestroy.c src/pspininit.c \ ## TIME_C_FILES libposix_a_SOURCES += src/adjtime.c src/time.c src/posixtimespecsubtract.c \ src/posixtimespectointerval.c src/posixintervaltotimespec.c \ - src/clockgetcpuclockid.c src/clockgetenableattr.c src/clockgetres.c \ - src/clockgettime.c src/clocksetenableattr.c src/clocksettime.c \ - src/nanosleep.c src/sleep.c src/usleep.c + src/posixtimespecabsolutetimeout.c src/clockgetcpuclockid.c \ + src/clockgetenableattr.c src/clockgetres.c src/clockgettime.c \ + src/clocksetenableattr.c src/clocksettime.c src/nanosleep.c src/sleep.c \ + src/usleep.c # the timer manager needs to be split further but only after its # dependence on the Classic API Timer Manager is removed. diff --git a/cpukit/posix/src/posixtimespecabsolutetimeout.c b/cpukit/posix/src/posixtimespecabsolutetimeout.c new file mode 100644 index 0000000000..df70c90533 --- /dev/null +++ b/cpukit/posix/src/posixtimespecabsolutetimeout.c @@ -0,0 +1,69 @@ +/* + * Convert abstime timeout to ticks + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* + * The abstime is a walltime. We turn it into an interval. + */ +int _POSIX_Absolute_timeout_to_ticks( + const struct timespec *abstime, + Watchdog_Interval *ticks_out +) +{ + struct timespec current_time; + struct timespec difference; + + if ( !abstime ) + return EINVAL; + + /* + * Error check the absolute time to timeout + */ +#if 0 + /* they are unsigned so this is impossible */ + if ( abstime->tv_sec < 0 || abstime->tv_nsec < 0 ) + return EINVAL; +#endif + + if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) + return EINVAL; + + (void) clock_gettime( CLOCK_REALTIME, ¤t_time ); + + /* + * Make sure the abstime is in the future + */ + if ( abstime->tv_sec < current_time.tv_sec ) + return EINVAL; + + if ( (abstime->tv_sec == current_time.tv_sec) && + (abstime->tv_nsec <= current_time.tv_nsec) ) + return EINVAL; + + _POSIX_Timespec_subtract( ¤t_time, abstime, &difference ); + + *ticks_out = _POSIX_Timespec_to_interval( &difference ); + + return 0; +} + -- cgit v1.2.3