summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/timespec.c
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-04-17 15:54:34 -0700
committerAnand Avati <avati@redhat.com>2014-04-24 14:41:48 -0700
commita3cb38e3edf005bef73da4c9cfd958474a14d50f (patch)
treea406029332a9eb096c14d441160bb670a42df8cb /libglusterfs/src/timespec.c
parent9c13471b109587a639662fc690384285bee02bc6 (diff)
build: MacOSX Porting fixes
git@forge.gluster.org:~schafdog/glusterfs-core/osx-glusterfs Working functionality on MacOSX - GlusterD (management daemon) - GlusterCLI (management cli) - GlusterFS FUSE (using OSXFUSE) - GlusterNFS (without NLM - issues with rpc.statd) Change-Id: I20193d3f8904388e47344e523b3787dbeab044ac BUG: 1089172 Signed-off-by: Harshavardhana <harsha@harshavardhana.net> Signed-off-by: Dennis Schafroth <dennis@schafroth.com> Tested-by: Harshavardhana <harsha@harshavardhana.net> Tested-by: Dennis Schafroth <dennis@schafroth.com> Reviewed-on: http://review.gluster.org/7503 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src/timespec.c')
-rw-r--r--libglusterfs/src/timespec.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c
index a0c281a1efb..5242ecc8cd0 100644
--- a/libglusterfs/src/timespec.c
+++ b/libglusterfs/src/timespec.c
@@ -10,54 +10,51 @@
#include <stdio.h>
#include <inttypes.h>
-#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || defined GF_BSD_HOST_OS
#include <time.h>
#include <sys/time.h>
-#endif
#if defined GF_DARWIN_HOST_OS
#include <mach/mach_time.h>
+static mach_timebase_info_data_t gf_timebase;
#endif
#include "logging.h"
-#include "time.h"
-
-
-void tv2ts (struct timeval tv, struct timespec *ts)
-{
- ts->tv_sec = tv.tv_sec;
- ts->tv_nsec = tv.tv_usec * 1000;
-}
+#include "timespec.h"
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))
return;
else {
struct timeval tv;
if (0 == gettimeofday(&tv, NULL))
- tv2ts(tv, ts);
+ TIMEVAL_TO_TIMESPEC(&tv, ts);
}
#elif defined GF_DARWIN_HOST_OS
- mach_timebase_info_data_t tb = { 0 };
- static double timebase = 0.0;
- uint64_t time = 0;
- mach_timebase_info (&tb);
+ uint64_t time = mach_absolute_time();
+ static double scaling = 0.0;
- timebase *= info.numer;
- timebase /= info.denom;
+ 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;
+ }
- time = mach_absolute_time();
- time *= timebase;
+ 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_nsec = (time - (ts->tv_sec * GIGA));
#endif /* Platform verification */
- gf_log_callingfn ("timer", GF_LOG_DEBUG, "%"PRIu64".%09"PRIu64,
+ /*
+ gf_log_callingfn ("timer", GF_LOG_TRACE, "%"GF_PRI_TIME".%09"GF_PRI_TIME,
ts->tv_sec, ts->tv_nsec);
+ */
}
void timespec_adjust_delta (struct timespec *ts, struct timespec delta)