summaryrefslogtreecommitdiffstats
path: root/src/nstime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nstime.c')
-rw-r--r--src/nstime.c76
1 files changed, 49 insertions, 27 deletions
diff --git a/src/nstime.c b/src/nstime.c
index aad2c26..cfb1c8e 100644
--- a/src/nstime.c
+++ b/src/nstime.c
@@ -97,6 +97,54 @@ nstime_divide(const nstime_t *time, const nstime_t *divisor)
return (time->ns / divisor->ns);
}
+#ifdef _WIN32
+static void
+nstime_get(nstime_t *time)
+{
+ FILETIME ft;
+ uint64_t ticks_100ns;
+
+ GetSystemTimeAsFileTime(&ft);
+ ticks_100ns = (((uint64_t)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
+
+ nstime_init(time, ticks_100ns * 100);
+}
+#elif JEMALLOC_HAVE_CLOCK_MONOTONIC_RAW
+static void
+nstime_get(nstime_t *time)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
+ nstime_init2(time, ts.tv_sec, ts.tv_nsec);
+}
+#elif JEMALLOC_HAVE_CLOCK_MONOTONIC
+static void
+nstime_get(nstime_t *time)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ nstime_init2(time, ts.tv_sec, ts.tv_nsec);
+}
+#elif JEMALLOC_HAVE_MACH_ABSOLUTE_TIME
+static void
+nstime_get(nstime_t *time)
+{
+
+ nstime_init(time, mach_absolute_time());
+}
+#else
+static void
+nstime_get(nstime_t *time)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ nstime_init2(time, tv.tv_sec, tv.tv_usec * 1000);
+}
+#endif
+
#ifdef JEMALLOC_JET
#undef nstime_update
#define nstime_update JEMALLOC_N(n_nstime_update)
@@ -107,33 +155,7 @@ nstime_update(nstime_t *time)
nstime_t old_time;
nstime_copy(&old_time, time);
-
-#ifdef _WIN32
- {
- FILETIME ft;
- uint64_t ticks;
- GetSystemTimeAsFileTime(&ft);
- ticks = (((uint64_t)ft.dwHighDateTime) << 32) |
- ft.dwLowDateTime;
- time->ns = ticks * 100;
- }
-#elif JEMALLOC_CLOCK_GETTIME
- {
- struct timespec ts;
-
- if (sysconf(_SC_MONOTONIC_CLOCK) > 0)
- clock_gettime(CLOCK_MONOTONIC, &ts);
- else
- clock_gettime(CLOCK_REALTIME, &ts);
- time->ns = ts.tv_sec * BILLION + ts.tv_nsec;
- }
-#else
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- time->ns = tv.tv_sec * BILLION + tv.tv_usec * 1000;
- }
-#endif
+ nstime_get(time);
/* Handle non-monotonic clocks. */
if (unlikely(nstime_compare(&old_time, time) > 0)) {