1 #ifndef BABELTRACE_TRACE_IR_EVENT_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_EVENT_INTERNAL_H
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 /* Protection: this file uses BT_LIB_LOG*() macros directly */
29 #ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H
30 # error Please define include <babeltrace/lib-logging-internal.h> before including this file.
33 #include <babeltrace/assert-pre-internal.h>
34 #include <babeltrace/babeltrace-internal.h>
35 #include <babeltrace/values.h>
36 #include <babeltrace/trace-ir/clock-value-internal.h>
37 #include <babeltrace/trace-ir/stream-class.h>
38 #include <babeltrace/trace-ir/stream.h>
39 #include <babeltrace/trace-ir/stream-internal.h>
40 #include <babeltrace/trace-ir/packet.h>
41 #include <babeltrace/trace-ir/packet-internal.h>
42 #include <babeltrace/trace-ir/fields.h>
43 #include <babeltrace/trace-ir/fields-internal.h>
44 #include <babeltrace/trace-ir/event-class-internal.h>
45 #include <babeltrace/trace-ir/field-wrapper-internal.h>
46 #include <babeltrace/object-internal.h>
47 #include <babeltrace/assert-internal.h>
50 #define BT_ASSERT_PRE_EVENT_HOT(_event) \
51 BT_ASSERT_PRE_HOT(((const struct bt_event *) (_event)), \
52 "Event", ": %!+e", (_event))
55 struct bt_object base
;
56 struct bt_event_class
*class;
57 struct bt_packet
*packet
;
58 struct bt_field_wrapper
*header_field
;
59 struct bt_field
*common_context_field
;
60 struct bt_field
*specific_context_field
;
61 struct bt_field
*payload_field
;
62 struct bt_clock_value
*default_cv
;
67 void bt_event_destroy(struct bt_event
*event
);
70 struct bt_event
*bt_event_new(struct bt_event_class
*event_class
);
73 void _bt_event_set_is_frozen(const struct bt_event
*event
, bool is_frozen
);
76 # define bt_event_set_is_frozen _bt_event_set_is_frozen
78 # define bt_event_set_is_frozen(_event, _is_frozen)
83 void _bt_event_reset_dev_mode(struct bt_event
*event
)
87 if (event
->header_field
) {
88 bt_field_set_is_frozen(
89 event
->header_field
->field
, false);
91 event
->header_field
->field
);
94 if (event
->common_context_field
) {
95 bt_field_set_is_frozen(
96 event
->common_context_field
, false);
98 event
->common_context_field
);
101 if (event
->specific_context_field
) {
102 bt_field_set_is_frozen(
103 event
->specific_context_field
, false);
104 bt_field_reset(event
->specific_context_field
);
107 if (event
->payload_field
) {
108 bt_field_set_is_frozen(
109 event
->payload_field
, false);
110 bt_field_reset(event
->payload_field
);
115 # define bt_event_reset_dev_mode _bt_event_reset_dev_mode
117 # define bt_event_reset_dev_mode(_x)
121 void bt_event_reset(struct bt_event
*event
)
124 BT_LIB_LOGD("Resetting event: %!+e", event
);
125 bt_event_set_is_frozen(event
, false);
127 if (event
->default_cv
) {
128 bt_clock_value_reset(event
->default_cv
);
131 bt_object_put_no_null_check(&event
->packet
->base
);
132 event
->packet
= NULL
;
136 void bt_event_recycle(struct bt_event
*event
)
138 struct bt_event_class
*event_class
;
141 BT_LIB_LOGD("Recycling event: %!+e", event
);
144 * Those are the important ordered steps:
146 * 1. Reset the event object (put any permanent reference it
147 * has, unfreeze it and its fields in developer mode, etc.),
148 * but do NOT put its class's reference. This event class
149 * contains the pool to which we're about to recycle this
150 * event object, so we must guarantee its existence thanks
151 * to this existing reference.
153 * 2. Move the event class reference to our `event_class`
154 * variable so that we can set the event's class member
155 * to NULL before recycling it. We CANNOT do this after
156 * we put the event class reference because this bt_object_put_ref()
157 * could destroy the event class, also destroying its
158 * event pool, thus also destroying our event object (this
159 * would result in an invalid write access).
161 * 3. Recycle the event object.
163 * 4. Put our event class reference.
165 bt_event_reset(event
);
166 event_class
= event
->class;
167 BT_ASSERT(event_class
);
169 bt_object_pool_recycle_object(&event_class
->event_pool
, event
);
170 bt_object_put_no_null_check(&event_class
->base
);
174 void bt_event_set_packet(struct bt_event
*event
, struct bt_packet
*packet
)
176 BT_ASSERT_PRE_NON_NULL(event
, "Event");
177 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
178 BT_ASSERT_PRE_EVENT_HOT(event
);
179 BT_ASSERT_PRE(bt_event_class_borrow_stream_class(
180 event
->class) == packet
->stream
->class,
181 "Packet's stream class and event's stream class differ: "
182 "%![event-]+e, %![packet-]+a", event
, packet
);
184 BT_ASSERT(!event
->packet
);
185 event
->packet
= packet
;
186 bt_object_get_no_null_check_no_parent_check(&event
->packet
->base
);
187 BT_LIB_LOGV("Set event's packet: %![event-]+e, %![packet-]+a",
192 struct bt_event
*bt_event_create(struct bt_event_class
*event_class
,
193 struct bt_packet
*packet
)
195 struct bt_event
*event
= NULL
;
197 BT_ASSERT(event_class
);
198 event
= bt_object_pool_create_object(&event_class
->event_pool
);
199 if (unlikely(!event
)) {
200 BT_LIB_LOGE("Cannot allocate one event from event class's event pool: "
201 "%![ec-]+E", event_class
);
205 if (likely(!event
->class)) {
206 event
->class = event_class
;
207 bt_object_get_no_null_check(&event_class
->base
);
211 bt_event_set_packet(event
, packet
);
218 #endif /* BABELTRACE_TRACE_IR_EVENT_INTERNAL_H */
This page took 0.039261 seconds and 5 git commands to generate.