summaryrefslogtreecommitdiffstats
path: root/src/nstime.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-10-11 05:15:10 (GMT)
committerJason Evans <jasone@canonware.com>2016-10-11 05:15:10 (GMT)
commit5f11fb7d43795e9e2f5d72c8a43a042baaee9b63 (patch)
tree24e3b4aeb23578b483b46f9804d0a6545aac5a8b /src/nstime.c
parentee0c74b77a24dc4fdaad2c950bcf621b6fa54095 (diff)
downloadjemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.zip
jemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.tar.gz
jemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.tar.bz2
Do not advance decay epoch when time goes backwards.
Instead, move the epoch backward in time. Additionally, add nstime_monotonic() and use it in debug builds to assert that time only goes backward if nstime_update() is using a non-monotonic time source.
Diffstat (limited to 'src/nstime.c')
-rw-r--r--src/nstime.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/nstime.c b/src/nstime.c
index cfb1c8e..c420c88 100644
--- a/src/nstime.c
+++ b/src/nstime.c
@@ -98,6 +98,7 @@ nstime_divide(const nstime_t *time, const nstime_t *divisor)
}
#ifdef _WIN32
+# define NSTIME_MONOTONIC true
static void
nstime_get(nstime_t *time)
{
@@ -110,6 +111,7 @@ nstime_get(nstime_t *time)
nstime_init(time, ticks_100ns * 100);
}
#elif JEMALLOC_HAVE_CLOCK_MONOTONIC_RAW
+# define NSTIME_MONOTONIC true
static void
nstime_get(nstime_t *time)
{
@@ -119,6 +121,7 @@ nstime_get(nstime_t *time)
nstime_init2(time, ts.tv_sec, ts.tv_nsec);
}
#elif JEMALLOC_HAVE_CLOCK_MONOTONIC
+# define NSTIME_MONOTONIC true
static void
nstime_get(nstime_t *time)
{
@@ -128,6 +131,7 @@ nstime_get(nstime_t *time)
nstime_init2(time, ts.tv_sec, ts.tv_nsec);
}
#elif JEMALLOC_HAVE_MACH_ABSOLUTE_TIME
+# define NSTIME_MONOTONIC true
static void
nstime_get(nstime_t *time)
{
@@ -135,6 +139,7 @@ nstime_get(nstime_t *time)
nstime_init(time, mach_absolute_time());
}
#else
+# define NSTIME_MONOTONIC false
static void
nstime_get(nstime_t *time)
{
@@ -146,6 +151,23 @@ nstime_get(nstime_t *time)
#endif
#ifdef JEMALLOC_JET
+#undef nstime_monotonic
+#define nstime_monotonic JEMALLOC_N(n_nstime_monotonic)
+#endif
+bool
+nstime_monotonic(void)
+{
+
+ return (NSTIME_MONOTONIC);
+#undef NSTIME_MONOTONIC
+}
+#ifdef JEMALLOC_JET
+#undef nstime_monotonic
+#define nstime_monotonic JEMALLOC_N(nstime_monotonic)
+nstime_monotonic_t *nstime_monotonic = JEMALLOC_N(n_nstime_monotonic);
+#endif
+
+#ifdef JEMALLOC_JET
#undef nstime_update
#define nstime_update JEMALLOC_N(n_nstime_update)
#endif