2017-04-18 07:17:02 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_NSTIME_H
|
|
|
|
#define JEMALLOC_INTERNAL_NSTIME_H
|
2016-02-22 03:25:02 +08:00
|
|
|
|
2017-04-18 07:17:02 +08:00
|
|
|
/* Maximum supported number of seconds (~584 years). */
|
|
|
|
#define NSTIME_SEC_MAX KQU(18446744072)
|
2021-11-17 06:51:07 +08:00
|
|
|
|
|
|
|
#define NSTIME_MAGIC ((uint32_t)0xb8a9ce37)
|
|
|
|
#ifdef JEMALLOC_DEBUG
|
|
|
|
# define NSTIME_ZERO_INITIALIZER {0, NSTIME_MAGIC}
|
|
|
|
#else
|
|
|
|
# define NSTIME_ZERO_INITIALIZER {0}
|
|
|
|
#endif
|
2017-04-18 07:17:02 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint64_t ns;
|
2021-11-17 06:51:07 +08:00
|
|
|
#ifdef JEMALLOC_DEBUG
|
|
|
|
uint32_t magic; /* Tracks if initialized. */
|
|
|
|
#endif
|
2017-04-18 07:17:02 +08:00
|
|
|
} nstime_t;
|
|
|
|
|
2019-12-19 05:38:14 +08:00
|
|
|
static const nstime_t zero = NSTIME_ZERO_INITIALIZER;
|
|
|
|
|
2017-04-18 07:17:02 +08:00
|
|
|
void nstime_init(nstime_t *time, uint64_t ns);
|
2017-05-02 14:10:42 +08:00
|
|
|
void nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec);
|
|
|
|
uint64_t nstime_ns(const nstime_t *time);
|
|
|
|
uint64_t nstime_sec(const nstime_t *time);
|
|
|
|
uint64_t nstime_msec(const nstime_t *time);
|
|
|
|
uint64_t nstime_nsec(const nstime_t *time);
|
|
|
|
void nstime_copy(nstime_t *time, const nstime_t *source);
|
|
|
|
int nstime_compare(const nstime_t *a, const nstime_t *b);
|
|
|
|
void nstime_add(nstime_t *time, const nstime_t *addend);
|
2017-05-13 03:30:33 +08:00
|
|
|
void nstime_iadd(nstime_t *time, uint64_t addend);
|
2017-05-02 14:10:42 +08:00
|
|
|
void nstime_subtract(nstime_t *time, const nstime_t *subtrahend);
|
2017-05-13 03:30:33 +08:00
|
|
|
void nstime_isubtract(nstime_t *time, uint64_t subtrahend);
|
2017-05-02 14:10:42 +08:00
|
|
|
void nstime_imultiply(nstime_t *time, uint64_t multiplier);
|
|
|
|
void nstime_idivide(nstime_t *time, uint64_t divisor);
|
|
|
|
uint64_t nstime_divide(const nstime_t *time, const nstime_t *divisor);
|
|
|
|
|
2016-10-11 13:15:10 +08:00
|
|
|
typedef bool (nstime_monotonic_t)(void);
|
2017-05-02 14:10:42 +08:00
|
|
|
extern nstime_monotonic_t *JET_MUTABLE nstime_monotonic;
|
2016-02-22 03:25:02 +08:00
|
|
|
|
2020-06-02 21:42:44 +08:00
|
|
|
typedef void (nstime_update_t)(nstime_t *);
|
2017-05-02 14:10:42 +08:00
|
|
|
extern nstime_update_t *JET_MUTABLE nstime_update;
|
2017-04-18 07:17:02 +08:00
|
|
|
|
2020-06-02 21:42:44 +08:00
|
|
|
typedef void (nstime_prof_update_t)(nstime_t *);
|
|
|
|
extern nstime_prof_update_t *JET_MUTABLE nstime_prof_update;
|
|
|
|
|
|
|
|
void nstime_init_update(nstime_t *time);
|
|
|
|
void nstime_prof_init_update(nstime_t *time);
|
|
|
|
|
|
|
|
enum prof_time_res_e {
|
|
|
|
prof_time_res_default = 0,
|
|
|
|
prof_time_res_high = 1
|
|
|
|
};
|
|
|
|
typedef enum prof_time_res_e prof_time_res_t;
|
|
|
|
|
|
|
|
extern prof_time_res_t opt_prof_time_res;
|
|
|
|
extern const char *prof_time_res_mode_names[];
|
2019-12-17 04:41:06 +08:00
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE void
|
|
|
|
nstime_init_zero(nstime_t *time) {
|
|
|
|
nstime_copy(time, &zero);
|
|
|
|
}
|
|
|
|
|
2019-12-19 05:38:14 +08:00
|
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
|
|
nstime_equals_zero(nstime_t *time) {
|
|
|
|
int diff = nstime_compare(time, &zero);
|
|
|
|
assert(diff >= 0);
|
|
|
|
return diff == 0;
|
|
|
|
}
|
|
|
|
|
2017-04-18 07:17:02 +08:00
|
|
|
#endif /* JEMALLOC_INTERNAL_NSTIME_H */
|