1 #ifndef BABELTRACE_GRAPH_CLOCK_SNAPSHOT_SET_H
2 #define BABELTRACE_GRAPH_CLOCK_SNAPSHOT_SET_H
5 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include "common/assert.h"
30 #include "clock-snapshot.h"
31 #include "clock-class.h"
33 /* Protection: this file uses BT_LIB_LOG*() macros directly */
34 #ifndef BT_LIB_LOG_SUPPORTED
35 # error Please include "lib/logging.h" before including this file.
38 struct bt_clock_snapshot_set
{
39 /* Unique objects owned by this */
40 GPtrArray
*clock_snapshots
;
42 /* Weak; points to one of the clock snapshots above */
43 struct bt_clock_snapshot
*default_cs
;
47 int bt_clock_snapshot_set_initialize(struct bt_clock_snapshot_set
*cs_set
)
51 cs_set
->clock_snapshots
= g_ptr_array_sized_new(1);
52 if (!cs_set
->clock_snapshots
) {
53 BT_LOGE_STR("Failed to allocate one GPtrArray.");
58 cs_set
->default_cs
= NULL
;
65 void bt_clock_snapshot_set_reset(struct bt_clock_snapshot_set
*cs_set
)
70 BT_ASSERT(cs_set
->clock_snapshots
);
72 for (i
= 0; i
< cs_set
->clock_snapshots
->len
; i
++) {
73 struct bt_clock_snapshot
*cs
= cs_set
->clock_snapshots
->pdata
[i
];
76 bt_clock_snapshot_reset(cs
);
79 cs_set
->default_cs
= NULL
;
83 void bt_clock_snapshot_set_finalize(struct bt_clock_snapshot_set
*cs_set
)
89 if (cs_set
->clock_snapshots
) {
90 for (i
= 0; i
< cs_set
->clock_snapshots
->len
; i
++) {
91 struct bt_clock_snapshot
*cs
=
92 cs_set
->clock_snapshots
->pdata
[i
];
95 bt_clock_snapshot_recycle(cs
);
98 g_ptr_array_free(cs_set
->clock_snapshots
, TRUE
);
101 cs_set
->default_cs
= NULL
;
105 int bt_clock_snapshot_set_set_clock_snapshot(struct bt_clock_snapshot_set
*cs_set
,
106 struct bt_clock_class
*cc
, uint64_t raw_value
)
109 struct bt_clock_snapshot
*clock_snapshot
= NULL
;
116 * Check if we already have a value for this clock class.
118 * TODO: When we have many clock classes, make this more
121 for (i
= 0; i
< cs_set
->clock_snapshots
->len
; i
++) {
122 struct bt_clock_snapshot
*cs
= cs_set
->clock_snapshots
->pdata
[i
];
126 if (cs
->clock_class
== cc
) {
132 if (!clock_snapshot
) {
133 clock_snapshot
= bt_clock_snapshot_create(cc
);
134 if (!clock_snapshot
) {
135 BT_LIB_LOGE("Cannot create a clock snapshot from a clock class: "
141 g_ptr_array_add(cs_set
->clock_snapshots
, clock_snapshot
);
144 bt_clock_snapshot_set_raw_value(clock_snapshot
, raw_value
);
151 void bt_clock_snapshot_set_set_default_clock_snapshot(
152 struct bt_clock_snapshot_set
*cs_set
, uint64_t raw_value
)
155 BT_ASSERT(cs_set
->default_cs
);
156 bt_clock_snapshot_set_raw_value(cs_set
->default_cs
, raw_value
);
159 #endif /* BABELTRACE_GRAPH_CLOCK_SNAPSHOT_SET_H */
This page took 0.035985 seconds and 4 git commands to generate.