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