X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Ftrace-ir%2Fevent.h;h=53130c4ba52c5dfb9157b592d9118485b514b1cd;hb=5a3fec55322bf221441f86d5ffedeb049d08d200;hp=002278ce88e1bb090e2e3e01ae6d23f9166f7b18;hpb=870631a2db01676b476dbee615aade0a22926bcd;p=babeltrace.git diff --git a/src/lib/trace-ir/event.h b/src/lib/trace-ir/event.h index 002278ce..53130c4b 100644 --- a/src/lib/trace-ir/event.h +++ b/src/lib/trace-ir/event.h @@ -1,36 +1,19 @@ -#ifndef BABELTRACE_TRACE_IR_EVENT_INTERNAL_H -#define BABELTRACE_TRACE_IR_EVENT_INTERNAL_H - /* + * SPDX-License-Identifier: MIT + * * Copyright 2017-2018 Philippe Proulx * Copyright 2013, 2014 Jérémie Galarneau - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. */ +#ifndef BABELTRACE_TRACE_IR_EVENT_INTERNAL_H +#define BABELTRACE_TRACE_IR_EVENT_INTERNAL_H + /* Protection: this file uses BT_LIB_LOG*() macros directly */ #ifndef BT_LIB_LOG_SUPPORTED # error Please include "lib/logging.h" before including this file. #endif -#include "lib/assert-pre.h" -#include "common/macros.h" +#include "lib/assert-cond.h" #include #include #include @@ -39,15 +22,15 @@ #include "lib/object.h" #include "common/assert.h" #include +#include #include "event-class.h" #include "field.h" -#include "field-wrapper.h" #include "packet.h" #include "stream.h" -#define BT_ASSERT_PRE_EVENT_HOT(_event) \ - BT_ASSERT_PRE_HOT(((const struct bt_event *) (_event)), \ +#define BT_ASSERT_PRE_DEV_EVENT_HOT(_event) \ + BT_ASSERT_PRE_DEV_HOT(((const struct bt_event *) (_event)), \ "Event", ": %!+e", (_event)) struct bt_event { @@ -56,22 +39,22 @@ struct bt_event { /* Owned by this */ struct bt_event_class *class; - /* Owned by this */ + /* Owned by this (can be `NULL`) */ struct bt_packet *packet; + /* Owned by this */ + struct bt_stream *stream; + struct bt_field *common_context_field; struct bt_field *specific_context_field; struct bt_field *payload_field; bool frozen; }; -BT_HIDDEN void bt_event_destroy(struct bt_event *event); -BT_HIDDEN struct bt_event *bt_event_new(struct bt_event_class *event_class); -BT_HIDDEN void _bt_event_set_is_frozen(const struct bt_event *event, bool is_frozen); #ifdef BT_DEV_MODE @@ -84,7 +67,7 @@ __attribute__((unused)) static inline void _bt_event_reset_dev_mode(struct bt_event *event) { - BT_ASSERT(event); + BT_ASSERT_DBG(event); if (event->common_context_field) { bt_field_set_is_frozen( @@ -115,11 +98,16 @@ void _bt_event_reset_dev_mode(struct bt_event *event) static inline void bt_event_reset(struct bt_event *event) { - BT_ASSERT(event); + BT_ASSERT_DBG(event); BT_LIB_LOGD("Resetting event: %!+e", event); bt_event_set_is_frozen(event, false); - bt_object_put_no_null_check(&event->packet->base); - event->packet = NULL; + bt_object_put_ref_no_null_check(&event->stream->base); + event->stream = NULL; + + if (event->packet) { + bt_object_put_ref_no_null_check(&event->packet->base); + event->packet = NULL; + } } static inline @@ -127,7 +115,7 @@ void bt_event_recycle(struct bt_event *event) { struct bt_event_class *event_class; - BT_ASSERT(event); + BT_ASSERT_DBG(event); BT_LIB_LOGD("Recycling event: %!+e", event); /* @@ -154,56 +142,10 @@ void bt_event_recycle(struct bt_event *event) */ bt_event_reset(event); event_class = event->class; - BT_ASSERT(event_class); + BT_ASSERT_DBG(event_class); event->class = NULL; bt_object_pool_recycle_object(&event_class->event_pool, event); - bt_object_put_no_null_check(&event_class->base); -} - -static inline -void bt_event_set_packet(struct bt_event *event, struct bt_packet *packet) -{ - BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_NON_NULL(packet, "Packet"); - BT_ASSERT_PRE_EVENT_HOT(event); - BT_ASSERT_PRE(bt_event_class_borrow_stream_class( - event->class) == packet->stream->class, - "Packet's stream class and event's stream class differ: " - "%![event-]+e, %![packet-]+a", event, packet); - - BT_ASSERT(!event->packet); - event->packet = packet; - bt_object_get_no_null_check_no_parent_check(&event->packet->base); - BT_LIB_LOGD("Set event's packet: %![event-]+e, %![packet-]+a", - event, packet); -} - -static inline -struct bt_event *bt_event_create(struct bt_event_class *event_class, - struct bt_packet *packet) -{ - struct bt_event *event = NULL; - - BT_ASSERT(event_class); - event = bt_object_pool_create_object(&event_class->event_pool); - if (G_UNLIKELY(!event)) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot allocate one event from event class's event pool: " - "%![ec-]+E", event_class); - goto end; - } - - if (G_LIKELY(!event->class)) { - event->class = event_class; - bt_object_get_no_null_check(&event_class->base); - } - - BT_ASSERT(packet); - bt_event_set_packet(event, packet); - goto end; - -end: - return event; + bt_object_put_ref_no_null_check(&event_class->base); } #endif /* BABELTRACE_TRACE_IR_EVENT_INTERNAL_H */