summaryrefslogtreecommitdiffstats
path: root/src/nstime.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2017-06-13 19:49:58 (GMT)
committerJason Evans <jasone@canonware.com>2017-06-13 19:51:09 (GMT)
commit5018fe3f0979b7f9db9930accdf7ee31071fd703 (patch)
tree894055b5ff4ccde3d9d782861d45af4664f12ad2 /src/nstime.c
parent04380e79f1e2428bd0ad000bbc6e3d2dfc6b66a5 (diff)
parentba29113e5a58caeb6b4a65b1db6d8efae79cae45 (diff)
downloadjemalloc-5.0.0.zip
jemalloc-5.0.0.tar.gz
jemalloc-5.0.0.tar.bz2
Merge branch 'dev'5.0.0
Diffstat (limited to 'src/nstime.c')
-rw-r--r--src/nstime.c140
1 files changed, 58 insertions, 82 deletions
diff --git a/src/nstime.c b/src/nstime.c
index 0948e29..71db353 100644
--- a/src/nstime.c
+++ b/src/nstime.c
@@ -1,78 +1,83 @@
-#include "jemalloc/internal/jemalloc_internal.h"
+#include "jemalloc/internal/jemalloc_preamble.h"
+#include "jemalloc/internal/jemalloc_internal_includes.h"
-#define BILLION UINT64_C(1000000000)
+#include "jemalloc/internal/nstime.h"
-void
-nstime_init(nstime_t *time, uint64_t ns)
-{
+#include "jemalloc/internal/assert.h"
+
+#define BILLION UINT64_C(1000000000)
+#define MILLION UINT64_C(1000000)
+void
+nstime_init(nstime_t *time, uint64_t ns) {
time->ns = ns;
}
void
-nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec)
-{
-
+nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec) {
time->ns = sec * BILLION + nsec;
}
uint64_t
-nstime_ns(const nstime_t *time)
-{
-
- return (time->ns);
+nstime_ns(const nstime_t *time) {
+ return time->ns;
}
uint64_t
-nstime_sec(const nstime_t *time)
-{
-
- return (time->ns / BILLION);
+nstime_msec(const nstime_t *time) {
+ return time->ns / MILLION;
}
uint64_t
-nstime_nsec(const nstime_t *time)
-{
+nstime_sec(const nstime_t *time) {
+ return time->ns / BILLION;
+}
- return (time->ns % BILLION);
+uint64_t
+nstime_nsec(const nstime_t *time) {
+ return time->ns % BILLION;
}
void
-nstime_copy(nstime_t *time, const nstime_t *source)
-{
-
+nstime_copy(nstime_t *time, const nstime_t *source) {
*time = *source;
}
int
-nstime_compare(const nstime_t *a, const nstime_t *b)
-{
-
- return ((a->ns > b->ns) - (a->ns < b->ns));
+nstime_compare(const nstime_t *a, const nstime_t *b) {
+ return (a->ns > b->ns) - (a->ns < b->ns);
}
void
-nstime_add(nstime_t *time, const nstime_t *addend)
-{
-
+nstime_add(nstime_t *time, const nstime_t *addend) {
assert(UINT64_MAX - time->ns >= addend->ns);
time->ns += addend->ns;
}
void
-nstime_subtract(nstime_t *time, const nstime_t *subtrahend)
-{
+nstime_iadd(nstime_t *time, uint64_t addend) {
+ assert(UINT64_MAX - time->ns >= addend);
+
+ time->ns += addend;
+}
+void
+nstime_subtract(nstime_t *time, const nstime_t *subtrahend) {
assert(nstime_compare(time, subtrahend) >= 0);
time->ns -= subtrahend->ns;
}
void
-nstime_imultiply(nstime_t *time, uint64_t multiplier)
-{
+nstime_isubtract(nstime_t *time, uint64_t subtrahend) {
+ assert(time->ns >= subtrahend);
+
+ time->ns -= subtrahend;
+}
+void
+nstime_imultiply(nstime_t *time, uint64_t multiplier) {
assert((((time->ns | multiplier) & (UINT64_MAX << (sizeof(uint64_t) <<
2))) == 0) || ((time->ns * multiplier) / multiplier == time->ns));
@@ -80,28 +85,23 @@ nstime_imultiply(nstime_t *time, uint64_t multiplier)
}
void
-nstime_idivide(nstime_t *time, uint64_t divisor)
-{
-
+nstime_idivide(nstime_t *time, uint64_t divisor) {
assert(divisor != 0);
time->ns /= divisor;
}
uint64_t
-nstime_divide(const nstime_t *time, const nstime_t *divisor)
-{
-
+nstime_divide(const nstime_t *time, const nstime_t *divisor) {
assert(divisor->ns != 0);
- return (time->ns / divisor->ns);
+ return time->ns / divisor->ns;
}
#ifdef _WIN32
# define NSTIME_MONOTONIC true
static void
-nstime_get(nstime_t *time)
-{
+nstime_get(nstime_t *time) {
FILETIME ft;
uint64_t ticks_100ns;
@@ -110,39 +110,34 @@ nstime_get(nstime_t *time)
nstime_init(time, ticks_100ns * 100);
}
-#elif JEMALLOC_HAVE_CLOCK_MONOTONIC_COARSE
+#elif defined(JEMALLOC_HAVE_CLOCK_MONOTONIC_COARSE)
# define NSTIME_MONOTONIC true
static void
-nstime_get(nstime_t *time)
-{
+nstime_get(nstime_t *time) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
nstime_init2(time, ts.tv_sec, ts.tv_nsec);
}
-#elif JEMALLOC_HAVE_CLOCK_MONOTONIC
+#elif defined(JEMALLOC_HAVE_CLOCK_MONOTONIC)
# define NSTIME_MONOTONIC true
static void
-nstime_get(nstime_t *time)
-{
+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
+#elif defined(JEMALLOC_HAVE_MACH_ABSOLUTE_TIME)
# define NSTIME_MONOTONIC true
static void
-nstime_get(nstime_t *time)
-{
-
+nstime_get(nstime_t *time) {
nstime_init(time, mach_absolute_time());
}
#else
# define NSTIME_MONOTONIC false
static void
-nstime_get(nstime_t *time)
-{
+nstime_get(nstime_t *time) {
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -150,30 +145,15 @@ 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);
+static bool
+nstime_monotonic_impl(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
+nstime_monotonic_t *JET_MUTABLE nstime_monotonic = nstime_monotonic_impl;
-#ifdef JEMALLOC_JET
-#undef nstime_update
-#define nstime_update JEMALLOC_N(n_nstime_update)
-#endif
-bool
-nstime_update(nstime_t *time)
-{
+static bool
+nstime_update_impl(nstime_t *time) {
nstime_t old_time;
nstime_copy(&old_time, time);
@@ -182,13 +162,9 @@ nstime_update(nstime_t *time)
/* Handle non-monotonic clocks. */
if (unlikely(nstime_compare(&old_time, time) > 0)) {
nstime_copy(time, &old_time);
- return (true);
+ return true;
}
- return (false);
+ return false;
}
-#ifdef JEMALLOC_JET
-#undef nstime_update
-#define nstime_update JEMALLOC_N(nstime_update)
-nstime_update_t *nstime_update = JEMALLOC_N(n_nstime_update);
-#endif
+nstime_update_t *JET_MUTABLE nstime_update = nstime_update_impl;