1 #ifndef BABELTRACE_TRACE_IR_EVENT_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_EVENT_INTERNAL_H
5 * Babeltrace - Trace IR: Event internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 /* Protection: this file uses BT_LIB_LOG*() macros directly */
31 #ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H
32 # error Please define include <babeltrace/lib-logging-internal.h> before including this file.
35 #include <babeltrace/assert-pre-internal.h>
36 #include <babeltrace/babeltrace-internal.h>
37 #include <babeltrace/values.h>
38 #include <babeltrace/trace-ir/clock-value-internal.h>
39 #include <babeltrace/trace-ir/stream-class.h>
40 #include <babeltrace/trace-ir/stream.h>
41 #include <babeltrace/trace-ir/stream-internal.h>
42 #include <babeltrace/trace-ir/packet.h>
43 #include <babeltrace/trace-ir/packet-internal.h>
44 #include <babeltrace/trace-ir/fields.h>
45 #include <babeltrace/trace-ir/fields-internal.h>
46 #include <babeltrace/trace-ir/event-class-internal.h>
47 #include <babeltrace/trace-ir/field-wrapper-internal.h>
48 #include <babeltrace/object-internal.h>
49 #include <babeltrace/assert-internal.h>
52 #define BT_ASSERT_PRE_EVENT_HOT(_event) \
53 BT_ASSERT_PRE_HOT((_event), "Event", ": %!+e", (_event))
56 struct bt_object base
;
57 struct bt_event_class
*class;
58 struct bt_packet
*packet
;
59 struct bt_field_wrapper
*header_field
;
60 struct bt_field
*common_context_field
;
61 struct bt_field
*specific_context_field
;
62 struct bt_field
*payload_field
;
63 struct bt_clock_value
*default_cv
;
68 void bt_event_destroy(struct bt_event
*event
);
71 struct bt_event
*bt_event_new(struct bt_event_class
*event_class
);
74 void _bt_event_set_is_frozen(struct bt_event
*event
, bool is_frozen
);
77 # define bt_event_set_is_frozen _bt_event_set_is_frozen
79 # define bt_event_set_is_frozen(_event, _is_frozen)
84 void _bt_event_reset_dev_mode(struct bt_event
*event
)
88 if (event
->header_field
) {
89 bt_field_set_is_frozen(
90 event
->header_field
->field
, false);
92 event
->header_field
->field
);
95 if (event
->common_context_field
) {
96 bt_field_set_is_frozen(
97 event
->common_context_field
, false);
99 event
->common_context_field
);
102 if (event
->specific_context_field
) {
103 bt_field_set_is_frozen(
104 event
->specific_context_field
, false);
105 bt_field_reset(event
->specific_context_field
);
108 if (event
->payload_field
) {
109 bt_field_set_is_frozen(
110 event
->payload_field
, false);
111 bt_field_reset(event
->payload_field
);
116 # define bt_event_reset_dev_mode _bt_event_reset_dev_mode
118 # define bt_event_reset_dev_mode(_x)
122 void bt_event_reset(struct bt_event
*event
)
125 BT_LIB_LOGD("Resetting event: %!+e", event
);
126 bt_event_set_is_frozen(event
, false);
128 if (event
->default_cv
) {
129 bt_clock_value_reset(event
->default_cv
);
132 bt_object_put_no_null_check(&event
->packet
->base
);
133 event
->packet
= NULL
;
137 void bt_event_recycle(struct bt_event
*event
)
139 struct bt_event_class
*event_class
;
142 BT_LIB_LOGD("Recycling event: %!+e", event
);
145 * Those are the important ordered steps:
147 * 1. Reset the event object (put any permanent reference it
148 * has, unfreeze it and its fields in developer mode, etc.),
149 * but do NOT put its class's reference. This event class
150 * contains the pool to which we're about to recycle this
151 * event object, so we must guarantee its existence thanks
152 * to this existing reference.
154 * 2. Move the event class reference to our `event_class`
155 * variable so that we can set the event's class member
156 * to NULL before recycling it. We CANNOT do this after
157 * we put the event class reference because this bt_put()
158 * could destroy the event class, also destroying its
159 * event pool, thus also destroying our event object (this
160 * would result in an invalid write access).
162 * 3. Recycle the event object.
164 * 4. Put our event class reference.
166 bt_event_reset(event
);
167 event_class
= event
->class;
168 BT_ASSERT(event_class
);
170 bt_object_pool_recycle_object(&event_class
->event_pool
, event
);
171 bt_object_put_no_null_check(&event_class
->base
);
175 void bt_event_set_packet(struct bt_event
*event
, struct bt_packet
*packet
)
177 BT_ASSERT_PRE_NON_NULL(event
, "Event");
178 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
179 BT_ASSERT_PRE_EVENT_HOT(event
);
180 BT_ASSERT_PRE(bt_event_class_borrow_stream_class(
181 event
->class) == packet
->stream
->class,
182 "Packet's stream class and event's stream class differ: "
183 "%![event-]+e, %![packet-]+a", event
, packet
);
185 BT_ASSERT(!event
->packet
);
186 event
->packet
= packet
;
187 bt_object_get_no_null_check_no_parent_check(&event
->packet
->base
);
188 BT_LIB_LOGV("Set event's packet: %![event-]+e, %![packet-]+a",
193 struct bt_event
*bt_event_create(struct bt_event_class
*event_class
,
194 struct bt_packet
*packet
)
196 struct bt_event
*event
= NULL
;
198 BT_ASSERT(event_class
);
199 event
= bt_object_pool_create_object(&event_class
->event_pool
);
200 if (unlikely(!event
)) {
201 BT_LIB_LOGE("Cannot allocate one event from event class's event pool: "
202 "%![ec-]+E", event_class
);
206 if (likely(!event
->class)) {
207 event
->class = event_class
;
208 bt_object_get_no_null_check(&event_class
->base
);
212 bt_event_set_packet(event
, packet
);
219 #endif /* BABELTRACE_TRACE_IR_EVENT_INTERNAL_H */
This page took 0.034293 seconds and 4 git commands to generate.