cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / trace-ir / clock-snapshot.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef BABELTRACE_TRACE_IR_CLOCK_SNAPSHOT_INTERNAL_H
8 #define BABELTRACE_TRACE_IR_CLOCK_SNAPSHOT_INTERNAL_H
9
10 #include "lib/object.h"
11 #include <stdbool.h>
12 #include <stdint.h>
13
14 #include "clock-class.h"
15 #include "utils.h"
16
17 struct bt_clock_class;
18
19 struct bt_clock_snapshot {
20 struct bt_object base;
21 struct bt_clock_class *clock_class;
22 uint64_t value_cycles;
23 bool ns_from_origin_overflows;
24 int64_t ns_from_origin;
25 bool is_set;
26 };
27
28 static inline
29 void bt_clock_snapshot_set(struct bt_clock_snapshot *clock_snapshot)
30 {
31 BT_ASSERT_DBG(clock_snapshot);
32 clock_snapshot->is_set = true;
33 }
34
35 static inline
36 void bt_clock_snapshot_reset(struct bt_clock_snapshot *clock_snapshot)
37 {
38 BT_ASSERT_DBG(clock_snapshot);
39 clock_snapshot->is_set = false;
40 }
41
42 static inline
43 void set_ns_from_origin(struct bt_clock_snapshot *clock_snapshot)
44 {
45 if (bt_util_ns_from_origin_clock_class(clock_snapshot->clock_class,
46 clock_snapshot->value_cycles,
47 &clock_snapshot->ns_from_origin)) {
48 clock_snapshot->ns_from_origin_overflows = true;
49 }
50 }
51
52 static inline
53 void bt_clock_snapshot_set_raw_value(struct bt_clock_snapshot *clock_snapshot,
54 uint64_t cycles)
55 {
56 BT_ASSERT_DBG(clock_snapshot);
57 clock_snapshot->value_cycles = cycles;
58 set_ns_from_origin(clock_snapshot);
59 bt_clock_snapshot_set(clock_snapshot);
60 }
61
62 void bt_clock_snapshot_destroy(struct bt_clock_snapshot *clock_snapshot);
63
64 struct bt_clock_snapshot *bt_clock_snapshot_new(struct bt_clock_class *clock_class);
65
66 struct bt_clock_snapshot *bt_clock_snapshot_create(
67 struct bt_clock_class *clock_class);
68
69 void bt_clock_snapshot_recycle(struct bt_clock_snapshot *clock_snapshot);
70
71 #endif /* BABELTRACE_TRACE_IR_CLOCK_SNAPSHOT_INTERNAL_H */
This page took 0.037041 seconds and 4 git commands to generate.