diff options
-rw-r--r-- | libglusterfs/src/glusterfs/timespec.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/libglusterfs.sym | 1 | ||||
-rw-r--r-- | libglusterfs/src/timespec.c | 22 | ||||
-rw-r--r-- | xlators/features/utime/src/utime-helpers.c | 2 |
4 files changed, 26 insertions, 1 deletions
diff --git a/libglusterfs/src/glusterfs/timespec.h b/libglusterfs/src/glusterfs/timespec.h index 871871d538c..bb9ab446a5f 100644 --- a/libglusterfs/src/glusterfs/timespec.h +++ b/libglusterfs/src/glusterfs/timespec.h @@ -21,6 +21,8 @@ void timespec_now(struct timespec *ts); void +timespec_now_realtime(struct timespec *ts); +void timespec_adjust_delta(struct timespec *ts, struct timespec delta); void timespec_sub(const struct timespec *begin, const struct timespec *end, diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym index 5d96a4c6386..2e83d3f1003 100644 --- a/libglusterfs/src/libglusterfs.sym +++ b/libglusterfs/src/libglusterfs.sym @@ -1072,6 +1072,7 @@ sys_accept tbf_init tbf_throttle timespec_now +timespec_now_realtime timespec_sub timespec_adjust_delta timespec_cmp diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c index 1b7cff37eb6..96cef5c6f07 100644 --- a/libglusterfs/src/timespec.c +++ b/libglusterfs/src/timespec.c @@ -70,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); diff --git a/xlators/features/utime/src/utime-helpers.c b/xlators/features/utime/src/utime-helpers.c index 79cc0145f50..29d9ad93561 100644 --- a/xlators/features/utime/src/utime-helpers.c +++ b/xlators/features/utime/src/utime-helpers.c @@ -17,7 +17,7 @@ gl_timespec_get(struct timespec *ts) #ifdef TIME_UTC timespec_get(ts, TIME_UTC); #else - timespec_now(ts); + timespec_now_realtime(ts); #endif } |