diff options
Diffstat (limited to 'libglusterfs/src/timespec.c')
| -rw-r--r-- | libglusterfs/src/timespec.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c index c0d4ab9315b..96cef5c6f07 100644 --- a/libglusterfs/src/timespec.c +++ b/libglusterfs/src/timespec.c @@ -19,10 +19,9 @@ static mach_timebase_info_data_t gf_timebase; #endif -#include "logging.h" -#include "timespec.h" -#include "libglusterfs-messages.h" -#include "common-utils.h" +#include "glusterfs/timespec.h" +#include "glusterfs/libglusterfs-messages.h" +#include "glusterfs/common-utils.h" void timespec_now(struct timespec *ts) @@ -71,6 +70,28 @@ timespec_now(struct timespec *ts) } void +timespec_now_realtime(struct timespec *ts) +{ +#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || \ + defined GF_BSD_HOST_OS + if (0 == clock_gettime(CLOCK_REALTIME, ts)) { + return; + } +#endif + + /* Fall back to gettimeofday()*/ + struct timeval tv = { + 0, + }; + if (0 == gettimeofday(&tv, NULL)) { + TIMEVAL_TO_TIMESPEC(&tv, ts); + return; + } + + return; +} + +void timespec_adjust_delta(struct timespec *ts, struct timespec delta) { ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000); |
