diff options
-rw-r--r-- | include/litmus.h | 6 | ||||
-rw-r--r-- | src/clocks.c | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/include/litmus.h b/include/litmus.h index 72f1ad4..2c5d4df 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -330,6 +330,12 @@ double cputime(void); | |||
330 | */ | 330 | */ |
331 | double wctime(void); | 331 | double wctime(void); |
332 | 332 | ||
333 | /** | ||
334 | * Obtain CLOCK_MONOTONIC time | ||
335 | * @return CLOCK_MONOTONIC time in seconds | ||
336 | */ | ||
337 | double monotime(void); | ||
338 | |||
333 | /***** semaphore allocation ******/ | 339 | /***** semaphore allocation ******/ |
334 | /** | 340 | /** |
335 | * Allocate a semaphore following the FMLP protocol | 341 | * Allocate a semaphore following the FMLP protocol |
diff --git a/src/clocks.c b/src/clocks.c index 74c2fb4..5af4c1f 100644 --- a/src/clocks.c +++ b/src/clocks.c | |||
@@ -24,6 +24,17 @@ double wctime(void) | |||
24 | return (tv.tv_sec + 1E-6 * tv.tv_usec); | 24 | return (tv.tv_sec + 1E-6 * tv.tv_usec); |
25 | } | 25 | } |
26 | 26 | ||
27 | /* current time, according to CLOCK_MONOTONIC */ | ||
28 | double monotime(void) | ||
29 | { | ||
30 | struct timespec ts; | ||
31 | int err; | ||
32 | err = clock_gettime(CLOCK_MONOTONIC, &ts); | ||
33 | if (err != 0) | ||
34 | perror("clock_gettime"); | ||
35 | return (ts.tv_sec + 1E-9 * ts.tv_nsec); | ||
36 | } | ||
37 | |||
27 | int lt_sleep(lt_t timeout) | 38 | int lt_sleep(lt_t timeout) |
28 | { | 39 | { |
29 | struct timespec delay; | 40 | struct timespec delay; |