Move to kernel style SPDX license identifiers
[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 "common/macros.h"
11 #include "lib/object.h"
12 #include <stdbool.h>
13 #include <stdint.h>
14
15 #include "clock-class.h"
16 #include "utils.h"
17
18 struct bt_clock_class;
19
20 struct bt_clock_snapshot {
21 struct bt_object base;
22 struct bt_clock_class *clock_class;
23 uint64_t value_cycles;
24 bool ns_from_origin_overflows;
25 int64_t ns_from_origin;
26 bool is_set;
27 };
28
29 static inline
30 void bt_clock_snapshot_set(struct bt_clock_snapshot *clock_snapshot)
31 {
32 BT_ASSERT_DBG(clock_snapshot);
33 clock_snapshot->is_set = true;
34 }
35
36 static inline
37 void bt_clock_snapshot_reset(struct bt_clock_snapshot *clock_snapshot)
38 {
39 BT_ASSERT_DBG(clock_snapshot);
40 clock_snapshot->is_set = false;
41 }
42
43 static inline
44 void set_ns_from_origin(struct bt_clock_snapshot *clock_snapshot)
45 {
46 if (bt_util_ns_from_origin_clock_class(clock_snapshot->clock_class,
47 clock_snapshot->value_cycles,
48 &clock_snapshot->ns_from_origin)) {
49 clock_snapshot->ns_from_origin_overflows = true;
50 }
51 }
52
53 static inline
54 void bt_clock_snapshot_set_raw_value(struct bt_clock_snapshot *clock_snapshot,
55 uint64_t cycles)
56 {
57 BT_ASSERT_DBG(clock_snapshot);
58 clock_snapshot->value_cycles = cycles;
59 set_ns_from_origin(clock_snapshot);
60 bt_clock_snapshot_set(clock_snapshot);
61 }
62
63 BT_HIDDEN
64 void bt_clock_snapshot_destroy(struct bt_clock_snapshot *clock_snapshot);
65
66 BT_HIDDEN
67 struct bt_clock_snapshot *bt_clock_snapshot_new(struct bt_clock_class *clock_class);
68
69 BT_HIDDEN
70 struct bt_clock_snapshot *bt_clock_snapshot_create(
71 struct bt_clock_class *clock_class);
72
73 BT_HIDDEN
74 void bt_clock_snapshot_recycle(struct bt_clock_snapshot *clock_snapshot);
75
76 #endif /* BABELTRACE_TRACE_IR_CLOCK_SNAPSHOT_INTERNAL_H */
This page took 0.030201 seconds and 4 git commands to generate.