diff options
author | Gluster Ant <bugzilla-bot@gluster.org> | 2018-09-12 17:52:45 +0530 |
---|---|---|
committer | Nigel Babu <nigelb@redhat.com> | 2018-09-12 17:52:45 +0530 |
commit | e16868dede6455cab644805af6fe1ac312775e13 (patch) | |
tree | 15aebdb4fff2d87cf8a72f836816b3aa634da58d /libglusterfs/src/timespec.c | |
parent | 45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff) |
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4
Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'libglusterfs/src/timespec.c')
-rw-r--r-- | libglusterfs/src/timespec.c | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c index 932a18c0103..d17506662ac 100644 --- a/libglusterfs/src/timespec.c +++ b/libglusterfs/src/timespec.c @@ -24,65 +24,69 @@ static mach_timebase_info_data_t gf_timebase; #include "libglusterfs-messages.h" #include "common-utils.h" -void timespec_now (struct timespec *ts) +void +timespec_now(struct timespec *ts) { -#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || defined GF_BSD_HOST_OS - if (0 == clock_gettime(CLOCK_MONOTONIC, ts)) { - /* All good */ - return; - } +#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || \ + defined GF_BSD_HOST_OS + if (0 == clock_gettime(CLOCK_MONOTONIC, ts)) { + /* All good */ + return; + } - /* Fall back, but there is hope in gettimeofday() syscall */ - struct timeval tv; - if (0 == gettimeofday(&tv, NULL)) { - /* Again, all good */ - TIMEVAL_TO_TIMESPEC(&tv, ts); - return; - } + /* Fall back, but there is hope in gettimeofday() syscall */ + struct timeval tv; + if (0 == gettimeofday(&tv, NULL)) { + /* Again, all good */ + TIMEVAL_TO_TIMESPEC(&tv, ts); + return; + } - /* If control hits here, there is surely a problem, - mainly because, as per man page too, these syscalls - shouldn't fail. Best way is to ABORT, because it is - not right */ - GF_ABORT ("gettimeofday() failed!!"); + /* If control hits here, there is surely a problem, + mainly because, as per man page too, these syscalls + shouldn't fail. Best way is to ABORT, because it is + not right */ + GF_ABORT("gettimeofday() failed!!"); #elif defined GF_DARWIN_HOST_OS - uint64_t time = mach_absolute_time(); - static double scaling = 0.0; + uint64_t time = mach_absolute_time(); + static double scaling = 0.0; - if (mach_timebase_info(&gf_timebase) != KERN_SUCCESS) { - gf_timebase.numer = 1; - gf_timebase.denom = 1; - } - if (gf_timebase.denom == 0) { - gf_timebase.numer = 1; - gf_timebase.denom = 1; - } + if (mach_timebase_info(&gf_timebase) != KERN_SUCCESS) { + gf_timebase.numer = 1; + gf_timebase.denom = 1; + } + if (gf_timebase.denom == 0) { + gf_timebase.numer = 1; + gf_timebase.denom = 1; + } - scaling = (double) gf_timebase.numer / (double) gf_timebase.denom; - time *= scaling; + scaling = (double)gf_timebase.numer / (double)gf_timebase.denom; + time *= scaling; - ts->tv_sec = (time * NANO); - ts->tv_nsec = (time - (ts->tv_sec * GIGA)); + ts->tv_sec = (time * NANO); + ts->tv_nsec = (time - (ts->tv_sec * GIGA)); #endif /* Platform verification */ } -void timespec_adjust_delta (struct timespec *ts, struct timespec delta) +void +timespec_adjust_delta(struct timespec *ts, struct timespec delta) { - ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000); - ts->tv_sec += ((ts->tv_nsec + delta.tv_nsec) / 1000000000); - ts->tv_sec += delta.tv_sec; + ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000); + ts->tv_sec += ((ts->tv_nsec + delta.tv_nsec) / 1000000000); + ts->tv_sec += delta.tv_sec; } -void timespec_sub (const struct timespec *begin, const struct timespec *end, - struct timespec *res) +void +timespec_sub(const struct timespec *begin, const struct timespec *end, + struct timespec *res) { - if (end->tv_nsec < begin->tv_nsec) { - res->tv_sec = end->tv_sec - begin->tv_sec - 1; - res->tv_nsec = end->tv_nsec + 1000000000 - begin->tv_nsec; - } else { - res->tv_sec = end->tv_sec - begin->tv_sec; - res->tv_nsec = end->tv_nsec - begin->tv_nsec; - } + if (end->tv_nsec < begin->tv_nsec) { + res->tv_sec = end->tv_sec - begin->tv_sec - 1; + res->tv_nsec = end->tv_nsec + 1000000000 - begin->tv_nsec; + } else { + res->tv_sec = end->tv_sec - begin->tv_sec; + res->tv_nsec = end->tv_nsec - begin->tv_nsec; + } } |