diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-12-16 04:49:23 -0500 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-12-16 04:49:23 -0500 |
| commit | 93f417fbf3aa358ffff40530b6cf5d2446dcd8b7 (patch) | |
| tree | d8bb609cb9c7bec4a0c7f766a0419460aedbd123 /src | |
| parent | 5184b9f57b7342229d72ff0784a0c21d653a2067 (diff) | |
Add monotime() wrapper for CLOCK_MONOTONIC
Diffstat (limited to 'src')
| -rw-r--r-- | src/clocks.c | 11 |
1 files changed, 11 insertions, 0 deletions
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; |
