aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-08-14 14:31:06 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2012-08-14 14:46:16 -0400
commit2312a91bde3baeb226ce78c444b18eaa7f80cf34 (patch)
tree3632d1c940c99f2b1217b9efc654635b93756975
parentf215a05c0ea23c7779b1a3a4361b4d88ddc73dc1 (diff)
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.
-rw-r--r--include/litmus.h3
-rw-r--r--src/clocks.c11
2 files changed, 14 insertions, 0 deletions
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)
129 return __NS_PER_MS * milliseconds; 129 return __NS_PER_MS * milliseconds;
130} 130}
131 131
132/* sleep for some number of nanoseconds */
133int lt_sleep(lt_t timeout);
134
132/* CPU time consumed so far in seconds */ 135/* CPU time consumed so far in seconds */
133double cputime(void); 136double cputime(void);
134 137
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 @@
3#include <sys/time.h> 3#include <sys/time.h>
4#include <time.h> 4#include <time.h>
5 5
6#include "litmus.h"
7
6/* CPU time consumed so far in seconds */ 8/* CPU time consumed so far in seconds */
7double cputime(void) 9double cputime(void)
8{ 10{
@@ -21,3 +23,12 @@ double wctime(void)
21 gettimeofday(&tv, NULL); 23 gettimeofday(&tv, NULL);
22 return (tv.tv_sec + 1E-6 * tv.tv_usec); 24 return (tv.tv_sec + 1E-6 * tv.tv_usec);
23} 25}
26
27int lt_sleep(lt_t timeout)
28{
29 struct timespec delay;
30
31 delay.tv_sec = timeout / 1000000000L;
32 delay.tv_nsec = timeout % 1000000000L;
33 return nanosleep(&delay, NULL);
34}