summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2006-11-15 15:34:45 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2006-11-15 15:34:45 +0000
commitba16717a62bd93431b6523a6b24beddcb232dca7 (patch)
treedc552f757bd2d7aadcc3f7ae28c03b75e50ade60
parent2006-11-15 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-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.
-rw-r--r--cpukit/ChangeLog5
-rw-r--r--cpukit/posix/Makefile.am7
-rw-r--r--cpukit/posix/src/posixtimespecabsolutetimeout.c69
3 files changed, 78 insertions, 3 deletions
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 <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am: Add file missed in previous commit.
+ * posix/src/posixtimespecabsolutetimeout.c: New file.
+
2006-11-15 Ralf Corsépius <ralf.corsepius@rtems.org>
* 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 <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, &current_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( &current_time, abstime, &difference );
+
+ *ticks_out = _POSIX_Timespec_to_interval( &difference );
+
+ return 0;
+}
+