X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Fevent.c;h=5f0948568cc38581eda580133e00e135d5223f6d;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=b997f209655724debcaec974bd75e9a847d443c5;hpb=56e18c4ce186892c36d7f2cb5078087425e60134;p=babeltrace.git diff --git a/lib/trace-ir/event.c b/lib/trace-ir/event.c index b997f209..5f094856 100644 --- a/lib/trace-ir/event.c +++ b/lib/trace-ir/event.c @@ -1,12 +1,7 @@ /* - * event.c - * - * Babeltrace trace IR - Event - * + * Copyright 2017-2018 Philippe Proulx * Copyright 2013, 2014 Jérémie Galarneau * - * Author: 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 @@ -27,45 +22,36 @@ */ #define BT_LOG_TAG "EVENT" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include BT_HIDDEN -void _bt_event_set_is_frozen(struct bt_event *event, bool is_frozen) +void _bt_event_set_is_frozen(const struct bt_event *event, bool is_frozen) { BT_ASSERT(event); BT_LIB_LOGD("Setting event's frozen state: %!+e, is-frozen=%d", event, is_frozen); - if (event->header_field) { - BT_LOGD_STR("Setting event's header field's frozen state."); - bt_field_set_is_frozen( - event->header_field->field, is_frozen); - } - if (event->common_context_field) { BT_LOGD_STR("Setting event's common context field's frozen state."); bt_field_set_is_frozen( @@ -84,55 +70,17 @@ void _bt_event_set_is_frozen(struct bt_event *event, bool is_frozen) is_frozen); } - event->frozen = is_frozen; + ((struct bt_event *) event)->frozen = is_frozen; BT_LOGD_STR("Setting event's packet's frozen state."); bt_packet_set_is_frozen(event->packet, is_frozen); } -static -void recycle_event_header_field(struct bt_field_wrapper *field_wrapper, - struct bt_stream_class *stream_class) -{ - BT_ASSERT(field_wrapper); - BT_LIB_LOGD("Recycling event header field: " - "addr=%p, %![sc-]+S, %![field-]+f", field_wrapper, - stream_class, field_wrapper->field); - bt_object_pool_recycle_object( - &stream_class->event_header_field_pool, - field_wrapper); -} - -static inline -struct bt_field_wrapper *create_event_header_field( - struct bt_stream_class *stream_class) -{ - struct bt_field_wrapper *field_wrapper = NULL; - - field_wrapper = bt_field_wrapper_create( - &stream_class->event_header_field_pool, - bt_stream_class_borrow_event_header_field_type(stream_class)); - if (!field_wrapper) { - goto error; - } - - goto end; - -error: - if (field_wrapper) { - recycle_event_header_field(field_wrapper, stream_class); - field_wrapper = NULL; - } - -end: - return field_wrapper; -} - BT_HIDDEN struct bt_event *bt_event_new(struct bt_event_class *event_class) { struct bt_event *event = NULL; struct bt_stream_class *stream_class; - struct bt_field_type *ft; + struct bt_field_class *fc; BT_ASSERT(event_class); event = g_new0(struct bt_event, 1); @@ -144,52 +92,33 @@ struct bt_event *bt_event_new(struct bt_event_class *event_class) bt_object_init_unique(&event->base); stream_class = bt_event_class_borrow_stream_class(event_class); BT_ASSERT(stream_class); - - if (bt_stream_class_borrow_event_header_field_type(stream_class)) { - event->header_field = create_event_header_field(stream_class); - if (!event->header_field) { - BT_LOGE_STR("Cannot create event header field."); - goto error; - } - } - - ft = bt_stream_class_borrow_event_common_context_field_type( - stream_class); - if (ft) { - event->common_context_field = bt_field_create(ft); + fc = stream_class->event_common_context_fc; + if (fc) { + event->common_context_field = bt_field_create(fc); if (!event->common_context_field) { /* bt_field_create() logs errors */ goto error; } } - ft = bt_event_class_borrow_specific_context_field_type(event_class); - if (ft) { - event->specific_context_field = bt_field_create(ft); + fc = event_class->specific_context_fc; + if (fc) { + event->specific_context_field = bt_field_create(fc); if (!event->specific_context_field) { /* bt_field_create() logs errors */ goto error; } } - ft = bt_event_class_borrow_payload_field_type(event_class); - if (ft) { - event->payload_field = bt_field_create(ft); + fc = event_class->payload_fc; + if (fc) { + event->payload_field = bt_field_create(fc); if (!event->payload_field) { /* bt_field_create() logs errors */ goto error; } } - if (stream_class->default_clock_class) { - event->default_cv = bt_clock_value_create( - stream_class->default_clock_class); - if (!event->default_cv) { - /* bt_clock_value_create() logs errors */ - goto error; - } - } - goto end; error: @@ -208,16 +137,22 @@ struct bt_event_class *bt_event_borrow_class(struct bt_event *event) return event->class; } +const struct bt_event_class *bt_event_borrow_class_const( + const struct bt_event *event) +{ + return bt_event_borrow_class((void *) event); +} + struct bt_stream *bt_event_borrow_stream(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); return event->packet ? event->packet->stream : NULL; } -struct bt_field *bt_event_borrow_header_field(struct bt_event *event) +const struct bt_stream *bt_event_borrow_stream_const( + const struct bt_event *event) { - BT_ASSERT_PRE_NON_NULL(event, "Event"); - return event->header_field ? event->header_field->field : NULL; + return bt_event_borrow_stream((void *) event); } struct bt_field *bt_event_borrow_common_context_field(struct bt_event *event) @@ -226,31 +161,37 @@ struct bt_field *bt_event_borrow_common_context_field(struct bt_event *event) return event->common_context_field; } +const struct bt_field *bt_event_borrow_common_context_field_const( + const struct bt_event *event) +{ + BT_ASSERT_PRE_NON_NULL(event, "Event"); + return event->common_context_field; +} + struct bt_field *bt_event_borrow_specific_context_field(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); return event->specific_context_field; } +const struct bt_field *bt_event_borrow_specific_context_field_const( + const struct bt_event *event) +{ + BT_ASSERT_PRE_NON_NULL(event, "Event"); + return event->specific_context_field; +} + struct bt_field *bt_event_borrow_payload_field(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); return event->payload_field; } -static -void release_event_header_field(struct bt_field_wrapper *field_wrapper, - struct bt_event *event) +const struct bt_field *bt_event_borrow_payload_field_const( + const struct bt_event *event) { - if (!event->class) { - bt_field_wrapper_destroy(field_wrapper); - } else { - struct bt_stream_class *stream_class = - bt_event_class_borrow_stream_class(event->class); - - BT_ASSERT(stream_class); - recycle_event_header_field(field_wrapper, stream_class); - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); + return event->payload_field; } BT_HIDDEN @@ -259,91 +200,39 @@ void bt_event_destroy(struct bt_event *event) BT_ASSERT(event); BT_LIB_LOGD("Destroying event: %!+e", event); - if (event->header_field) { - BT_LOGD_STR("Releasing event's header field."); - release_event_header_field(event->header_field, event); - } - if (event->common_context_field) { BT_LOGD_STR("Destroying event's stream event context field."); bt_field_destroy(event->common_context_field); + event->common_context_field = NULL; } if (event->specific_context_field) { BT_LOGD_STR("Destroying event's context field."); bt_field_destroy(event->specific_context_field); + event->specific_context_field = NULL; } if (event->payload_field) { BT_LOGD_STR("Destroying event's payload field."); bt_field_destroy(event->payload_field); + event->payload_field = NULL; } BT_LOGD_STR("Putting event's class."); - bt_put(event->class); - - if (event->default_cv) { - bt_clock_value_recycle(event->default_cv); - } - + bt_object_put_ref(event->class); BT_LOGD_STR("Putting event's packet."); - bt_put(event->packet); + BT_OBJECT_PUT_REF_AND_RESET(event->packet); g_free(event); } -int bt_event_set_default_clock_value(struct bt_event *event, - uint64_t value_cycles) -{ - struct bt_stream_class *sc; - - BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_EVENT_HOT(event); - sc = bt_event_class_borrow_stream_class_inline(event->class); - BT_ASSERT(sc); - BT_ASSERT_PRE(sc->default_clock_class, - "Event's stream class has no default clock class: " - "%![ev-]+e, %![sc-]+S", event, sc); - BT_ASSERT(event->default_cv); - bt_clock_value_set_value_inline(event->default_cv, value_cycles); - BT_LIB_LOGV("Set event's default clock value: %![event-]+e, " - "value=%" PRIu64, event, value_cycles); - return 0; -} - -enum bt_clock_value_status bt_event_borrow_default_clock_value( - struct bt_event *event, struct bt_clock_value **clock_value) -{ - BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)"); - *clock_value = event->default_cv; - return BT_CLOCK_VALUE_STATUS_KNOWN; -} - struct bt_packet *bt_event_borrow_packet(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); return event->packet; } -int bt_event_move_header(struct bt_event *event, - struct bt_event_header_field *header_field) +const struct bt_packet *bt_event_borrow_packet_const( + const struct bt_event *event) { - struct bt_stream_class *stream_class; - struct bt_field_wrapper *field_wrapper = (void *) header_field; - - BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field"); - BT_ASSERT_PRE_EVENT_HOT(event); - stream_class = bt_event_class_borrow_stream_class_inline(event->class); - BT_ASSERT_PRE(stream_class->event_header_ft, - "Stream class has no event header field type: %!+S", - stream_class); - - /* Recycle current header field: always exists */ - BT_ASSERT(event->header_field); - recycle_event_header_field(event->header_field, stream_class); - - /* Move new field */ - event->header_field = field_wrapper; - return 0; + return bt_event_borrow_packet((void *) event); }