1#ifndef JEMALLOC_INTERNAL_NSTIME_H
2#define JEMALLOC_INTERNAL_NSTIME_H
3
4/* Maximum supported number of seconds (~584 years). */
5#define NSTIME_SEC_MAX KQU(18446744072)
6
7#define NSTIME_MAGIC ((uint32_t)0xb8a9ce37)
8#ifdef JEMALLOC_DEBUG
9# define NSTIME_ZERO_INITIALIZER {0, NSTIME_MAGIC}
10#else
11# define NSTIME_ZERO_INITIALIZER {0}
12#endif
13
14typedef struct {
15 uint64_t ns;
16#ifdef JEMALLOC_DEBUG
17 uint32_t magic; /* Tracks if initialized. */
18#endif
19} nstime_t;
20
21static const nstime_t nstime_zero = NSTIME_ZERO_INITIALIZER;
22
23void nstime_init(nstime_t *time, uint64_t ns);
24void nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec);
25uint64_t nstime_ns(const nstime_t *time);
26uint64_t nstime_sec(const nstime_t *time);
27uint64_t nstime_msec(const nstime_t *time);
28uint64_t nstime_nsec(const nstime_t *time);
29void nstime_copy(nstime_t *time, const nstime_t *source);
30int nstime_compare(const nstime_t *a, const nstime_t *b);
31void nstime_add(nstime_t *time, const nstime_t *addend);
32void nstime_iadd(nstime_t *time, uint64_t addend);
33void nstime_subtract(nstime_t *time, const nstime_t *subtrahend);
34void nstime_isubtract(nstime_t *time, uint64_t subtrahend);
35void nstime_imultiply(nstime_t *time, uint64_t multiplier);
36void nstime_idivide(nstime_t *time, uint64_t divisor);
37uint64_t nstime_divide(const nstime_t *time, const nstime_t *divisor);
38uint64_t nstime_ns_since(const nstime_t *past);
39
40typedef bool (nstime_monotonic_t)(void);
41extern nstime_monotonic_t *JET_MUTABLE nstime_monotonic;
42
43typedef void (nstime_update_t)(nstime_t *);
44extern nstime_update_t *JET_MUTABLE nstime_update;
45
46typedef void (nstime_prof_update_t)(nstime_t *);
47extern nstime_prof_update_t *JET_MUTABLE nstime_prof_update;
48
49void nstime_init_update(nstime_t *time);
50void nstime_prof_init_update(nstime_t *time);
51
52enum prof_time_res_e {
53 prof_time_res_default = 0,
54 prof_time_res_high = 1
55};
56typedef enum prof_time_res_e prof_time_res_t;
57
58extern prof_time_res_t opt_prof_time_res;
59extern const char *prof_time_res_mode_names[];
60
61JEMALLOC_ALWAYS_INLINE void
62nstime_init_zero(nstime_t *time) {
63 nstime_copy(time, &nstime_zero);
64}
65
66JEMALLOC_ALWAYS_INLINE bool
67nstime_equals_zero(nstime_t *time) {
68 int diff = nstime_compare(time, &nstime_zero);
69 assert(diff >= 0);
70 return diff == 0;
71}
72
73#endif /* JEMALLOC_INTERNAL_NSTIME_H */
74