aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-10-07 08:47:16 -0700
committerJason Evans <jasone@canonware.com>2016-10-10 11:40:46 -0700
commitb732c395b7755622dd469fb27a463adcfd3b3152 (patch)
treeca8896b4c5f08b4e735bb9f5bca876f514f8cbd5 /include
parent5d8db15db91c85d47b343cfc07fc6ea736f0de48 (diff)
downloadjemalloc-b732c395b7755622dd469fb27a463adcfd3b3152.tar.gz
Refine nstime_update().
Add missing #include <time.h>. The critical time facilities appear to have been transitively included via unistd.h and sys/time.h, but in principle this omission was capable of having caused clock_gettime(CLOCK_MONOTONIC, ...) to have been overlooked in favor of gettimeofday(), which in turn could cause spurious non-monotonic time updates. Refactor nstime_get() out of nstime_update() and add configure tests for all variants. Add CLOCK_MONOTONIC_RAW support (Linux-specific) and mach_absolute_time() support (OS X-specific). Do not fall back to clock_gettime(CLOCK_REALTIME, ...). This was a fragile Linux-specific workaround, which we're unlikely to use at all now that clock_gettime(CLOCK_MONOTONIC_RAW, ...) is supported, and if we have no choice besides non-monotonic clocks, gettimeofday() is only incrementally worse.
Diffstat (limited to 'include')
-rw-r--r--include/jemalloc/internal/jemalloc_internal_decls.h4
-rw-r--r--include/jemalloc/internal/jemalloc_internal_defs.h.in15
-rw-r--r--include/jemalloc/internal/nstime.h3
3 files changed, 19 insertions, 3 deletions
diff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h
index 2b8ca5d..910b2fc 100644
--- a/include/jemalloc/internal/jemalloc_internal_decls.h
+++ b/include/jemalloc/internal/jemalloc_internal_decls.h
@@ -19,6 +19,10 @@
# include <pthread.h>
# include <errno.h>
# include <sys/time.h>
+# include <time.h>
+# ifdef JEMALLOC_HAVE_MACH_ABSOLUTE_TIME
+# include <mach/mach_time.h>
+# endif
#endif
#include <sys/types.h>
diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in
index 22396b7..d10c8a4 100644
--- a/include/jemalloc/internal/jemalloc_internal_defs.h.in
+++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in
@@ -77,6 +77,21 @@
#undef JEMALLOC_HAVE_ISSETUGID
/*
+ * Defined if clock_gettime(CLOCK_MONOTONIC_RAW, ...) is available.
+ */
+#undef JEMALLOC_HAVE_CLOCK_MONOTONIC_RAW
+
+/*
+ * Defined if clock_gettime(CLOCK_MONOTONIC, ...) is available.
+ */
+#undef JEMALLOC_HAVE_CLOCK_MONOTONIC
+
+/*
+ * Defined if mach_absolute_time() is available.
+ */
+#undef JEMALLOC_HAVE_MACH_ABSOLUTE_TIME
+
+/*
* Defined if _malloc_thread_cleanup() exists. At least in the case of
* FreeBSD, pthread_key_create() allocates, which if used during malloc
* bootstrapping will cause recursion into the pthreads library. Therefore, if
diff --git a/include/jemalloc/internal/nstime.h b/include/jemalloc/internal/nstime.h
index dc293b7..c892bac 100644
--- a/include/jemalloc/internal/nstime.h
+++ b/include/jemalloc/internal/nstime.h
@@ -1,9 +1,6 @@
/******************************************************************************/
#ifdef JEMALLOC_H_TYPES
-#define JEMALLOC_CLOCK_GETTIME defined(_POSIX_MONOTONIC_CLOCK) \
- && _POSIX_MONOTONIC_CLOCK >= 0
-
typedef struct nstime_s nstime_t;
/* Maximum supported number of seconds (~584 years). */