2 * Eddie Kohler, Yandong Mao, Robert Morris
3 * Copyright (c) 2012-2013 President and Fellows of Harvard College
4 * Copyright (c) 2012-2013 Massachusetts Institute of Technology
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, subject to the conditions
9 * listed in the Masstree LICENSE file. These conditions include: you must
10 * preserve this copyright notice, and you cannot mention the copyright
11 * holders in advertising related to the Software without their permission.
12 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13 * notice is a summary of the Masstree LICENSE file; the license in that file
18 #include "compiler.hh"
23 #if HAVE_INT64_T_IS_LONG_LONG
24 #define PRIuKVTS "llu"
28 #define PRIKVTSPARTS "%lu.%06lu"
30 #define KVTS_HIGHPART(t) ((unsigned long) ((t) >> 32))
31 #define KVTS_LOWPART(t) ((unsigned long) (uint32_t) (t))
33 typedef uint64_t kvtimestamp_t;
35 inline kvtimestamp_t timestamp() {
38 return ((kvtimestamp_t) tv.tv_sec << 32) | (unsigned int)tv.tv_usec;
41 inline kvtimestamp_t timestamp_sub(kvtimestamp_t a, kvtimestamp_t b) {
43 if (KVTS_LOWPART(a) > 999999)
44 a -= ((kvtimestamp_t) 1 << 32) - 1000000;
48 extern kvtimestamp_t initial_timestamp;
53 return tv.tv_sec + tv.tv_usec / 1000000.0;
56 inline struct timespec &set_timespec(struct timespec &x, double y) {
57 double ipart = floor(y);
58 x.tv_sec = (long) ipart;
59 x.tv_nsec = (long) ((y - ipart) * 1e9);