diff options
author | Tom Gundersen <teg@jklm.no> | 2015-08-28 12:01:46 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-08-28 12:01:46 +0200 |
commit | 84d449b55215dfe81305d3ee89606fdc17150ad6 (patch) | |
tree | ebb5250b2cedcb493a435119a6f408a1f72b6162 /src/basic/time-util.c | |
parent | 9c92a077b667fe3947cc8a9caa197dea8b80b8e0 (diff) | |
parent | e049fa164f0062caab6e53113b3fd7102dc739ce (diff) |
Merge pull request #1063 from poettering/dbus-interface-from-type
cgls/cgtop: a variety of modernizations
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 3d8d5d7568..afc6a6eb24 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -37,6 +37,14 @@ usec_t now(clockid_t clock_id) { return timespec_load(&ts); } +nsec_t now_nsec(clockid_t clock_id) { + struct timespec ts; + + assert_se(clock_gettime(clock_id, &ts) == 0); + + return timespec_load_nsec(&ts); +} + dual_timestamp* dual_timestamp_get(dual_timestamp *ts) { assert(ts); @@ -130,6 +138,18 @@ usec_t timespec_load(const struct timespec *ts) { (usec_t) ts->tv_nsec / NSEC_PER_USEC; } +nsec_t timespec_load_nsec(const struct timespec *ts) { + assert(ts); + + if (ts->tv_sec == (time_t) -1 && + ts->tv_nsec == (long) -1) + return NSEC_INFINITY; + + return + (nsec_t) ts->tv_sec * NSEC_PER_SEC + + (nsec_t) ts->tv_nsec; +} + struct timespec *timespec_store(struct timespec *ts, usec_t u) { assert(ts); |