1 #ifndef BABELTRACE_TRACE_IR_EVENT_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_EVENT_INTERNAL_H
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 /* Protection: this file uses BT_LIB_LOG*() macros directly */
28 #ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H
29 # error Please define include <babeltrace/lib-logging-internal.h> before including this file.
32 #include <babeltrace/assert-pre-internal.h>
33 #include <babeltrace/babeltrace-internal.h>
34 #include <babeltrace/value.h>
35 #include <babeltrace/trace-ir/clock-snapshot-internal.h>
36 #include <babeltrace/trace-ir/stream-class.h>
37 #include <babeltrace/trace-ir/stream.h>
38 #include <babeltrace/trace-ir/stream-internal.h>
39 #include <babeltrace/trace-ir/packet.h>
40 #include <babeltrace/trace-ir/packet-internal.h>
41 #include <babeltrace/trace-ir/field.h>
42 #include <babeltrace/trace-ir/field-internal.h>
43 #include <babeltrace/trace-ir/event-class-internal.h>
44 #include <babeltrace/trace-ir/field-wrapper-internal.h>
45 #include <babeltrace/object-internal.h>
46 #include <babeltrace/assert-internal.h>
49 #define BT_ASSERT_PRE_EVENT_HOT(_event) \
50 BT_ASSERT_PRE_HOT(((const struct bt_event *) (_event)), \
51 "Event", ": %!+e", (_event))
54 struct bt_object base
;
57 struct bt_event_class
*class;
60 struct bt_packet
*packet
;
62 struct bt_field_wrapper
*header_field
;
63 struct bt_field
*common_context_field
;
64 struct bt_field
*specific_context_field
;
65 struct bt_field
*payload_field
;
66 struct bt_clock_snapshot
*default_cs
;
71 void bt_event_destroy(struct bt_event
*event
);
74 struct bt_event
*bt_event_new(struct bt_event_class
*event_class
);
77 void _bt_event_set_is_frozen(const struct bt_event
*event
, bool is_frozen
);
80 # define bt_event_set_is_frozen _bt_event_set_is_frozen
82 # define bt_event_set_is_frozen(_event, _is_frozen)
87 void _bt_event_reset_dev_mode(struct bt_event
*event
)
91 if (event
->header_field
) {
92 bt_field_set_is_frozen(
93 event
->header_field
->field
, false);
95 event
->header_field
->field
);
98 if (event
->common_context_field
) {
99 bt_field_set_is_frozen(
100 event
->common_context_field
, false);
102 event
->common_context_field
);
105 if (event
->specific_context_field
) {
106 bt_field_set_is_frozen(
107 event
->specific_context_field
, false);
108 bt_field_reset(event
->specific_context_field
);
111 if (event
->payload_field
) {
112 bt_field_set_is_frozen(
113 event
->payload_field
, false);
114 bt_field_reset(event
->payload_field
);
119 # define bt_event_reset_dev_mode _bt_event_reset_dev_mode
121 # define bt_event_reset_dev_mode(_x)
125 void bt_event_reset(struct bt_event
*event
)
128 BT_LIB_LOGD("Resetting event: %!+e", event
);
129 bt_event_set_is_frozen(event
, false);
131 if (event
->default_cs
) {
132 bt_clock_snapshot_reset(event
->default_cs
);
135 bt_object_put_no_null_check(&event
->packet
->base
);
136 event
->packet
= NULL
;
140 void bt_event_recycle(struct bt_event
*event
)
142 struct bt_event_class
*event_class
;
145 BT_LIB_LOGD("Recycling event: %!+e", event
);
148 * Those are the important ordered steps:
150 * 1. Reset the event object (put any permanent reference it
151 * has, unfreeze it and its fields in developer mode, etc.),
152 * but do NOT put its class's reference. This event class
153 * contains the pool to which we're about to recycle this
154 * event object, so we must guarantee its existence thanks
155 * to this existing reference.
157 * 2. Move the event class reference to our `event_class`
158 * variable so that we can set the event's class member
159 * to NULL before recycling it. We CANNOT do this after
160 * we put the event class reference because this bt_object_put_ref()
161 * could destroy the event class, also destroying its
162 * event pool, thus also destroying our event object (this
163 * would result in an invalid write access).
165 * 3. Recycle the event object.
167 * 4. Put our event class reference.
169 bt_event_reset(event
);
170 event_class
= event
->class;
171 BT_ASSERT(event_class
);
173 bt_object_pool_recycle_object(&event_class
->event_pool
, event
);
174 bt_object_put_no_null_check(&event_class
->base
);
178 void bt_event_set_packet(struct bt_event
*event
, struct bt_packet
*packet
)
180 BT_ASSERT_PRE_NON_NULL(event
, "Event");
181 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
182 BT_ASSERT_PRE_EVENT_HOT(event
);
183 BT_ASSERT_PRE(bt_event_class_borrow_stream_class(
184 event
->class) == packet
->stream
->class,
185 "Packet's stream class and event's stream class differ: "
186 "%![event-]+e, %![packet-]+a", event
, packet
);
188 BT_ASSERT(!event
->packet
);
189 event
->packet
= packet
;
190 bt_object_get_no_null_check_no_parent_check(&event
->packet
->base
);
191 BT_LIB_LOGV("Set event's packet: %![event-]+e, %![packet-]+a",
196 struct bt_event
*bt_event_create(struct bt_event_class
*event_class
,
197 struct bt_packet
*packet
)
199 struct bt_event
*event
= NULL
;
201 BT_ASSERT(event_class
);
202 event
= bt_object_pool_create_object(&event_class
->event_pool
);
203 if (unlikely(!event
)) {
204 BT_LIB_LOGE("Cannot allocate one event from event class's event pool: "
205 "%![ec-]+E", event_class
);
209 if (likely(!event
->class)) {
210 event
->class = event_class
;
211 bt_object_get_no_null_check(&event_class
->base
);
215 bt_event_set_packet(event
, packet
);
222 #endif /* BABELTRACE_TRACE_IR_EVENT_INTERNAL_H */
This page took 0.034432 seconds and 4 git commands to generate.