diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2006-11-15 15:34:45 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2006-11-15 15:34:45 +0000 |
commit | ba16717a62bd93431b6523a6b24beddcb232dca7 (patch) | |
tree | dc552f757bd2d7aadcc3f7ae28c03b75e50ade60 /cpukit/posix/src/posixtimespecabsolutetimeout.c | |
parent | 2006-11-15 Joel Sherrill <joel@OARcorp.com> (diff) | |
download | rtems-ba16717a62bd93431b6523a6b24beddcb232dca7.tar.bz2 |
2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* posix/Makefile.am: Add file missed in previous commit.
* posix/src/posixtimespecabsolutetimeout.c: New file.
Diffstat (limited to 'cpukit/posix/src/posixtimespecabsolutetimeout.c')
-rw-r--r-- | cpukit/posix/src/posixtimespecabsolutetimeout.c | 69 |
1 files changed, 69 insertions, 0 deletions
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 <stdarg.h> + +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <semaphore.h> +#include <limits.h> + +#include <rtems/system.h> +#include <rtems/score/object.h> +#include <rtems/posix/semaphore.h> +#include <rtems/posix/time.h> +#include <rtems/seterr.h> + +/* + * 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; +} + |