From 2312a91bde3baeb226ce78c444b18eaa7f80cf34 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Tue, 14 Aug 2012 20:31:06 +0200 Subject: Implement lt_sleep() syscall wrapper Wrap nanosleep() to make sleeping for a given number of nanoseconds easier, using the LITMUS^RT time type lt_t. --- include/litmus.h | 3 +++ src/clocks.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/litmus.h b/include/litmus.h index e4b619e..677f9a9 100644 --- a/include/litmus.h +++ b/include/litmus.h @@ -129,6 +129,9 @@ static inline lt_t ms2lt(unsigned long milliseconds) return __NS_PER_MS * milliseconds; } +/* sleep for some number of nanoseconds */ +int lt_sleep(lt_t timeout); + /* CPU time consumed so far in seconds */ double cputime(void); diff --git a/src/clocks.c b/src/clocks.c index fcb94e5..74c2fb4 100644 --- a/src/clocks.c +++ b/src/clocks.c @@ -3,6 +3,8 @@ #include #include +#include "litmus.h" + /* CPU time consumed so far in seconds */ double cputime(void) { @@ -21,3 +23,12 @@ double wctime(void) gettimeofday(&tv, NULL); return (tv.tv_sec + 1E-6 * tv.tv_usec); } + +int lt_sleep(lt_t timeout) +{ + struct timespec delay; + + delay.tv_sec = timeout / 1000000000L; + delay.tv_nsec = timeout % 1000000000L; + return nanosleep(&delay, NULL); +} -- cgit v1.2.2