X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Fpacket.c;h=51bce30e9b932f9182e9a3676f8e6a4aced4209e;hb=e6276565e1dbc12fa132cf1b59376580c0d94330;hp=d6677212ca6672994a857f6997e15cd75dbe98a0;hpb=56e18c4ce186892c36d7f2cb5078087425e60134;p=babeltrace.git diff --git a/lib/trace-ir/packet.c b/lib/trace-ir/packet.c index d6677212..51bce30e 100644 --- a/lib/trace-ir/packet.c +++ b/lib/trace-ir/packet.c @@ -1,8 +1,4 @@ /* - * packet.c - * - * Babeltrace trace IR - Stream packet - * * Copyright 2016 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -29,6 +25,7 @@ #include #include +#include #include #include #include @@ -40,7 +37,7 @@ #include #include #include -#include +#include #include #include @@ -53,20 +50,38 @@ struct bt_stream *bt_packet_borrow_stream(struct bt_packet *packet) return packet->stream; } +const struct bt_stream *bt_packet_borrow_stream_const( + const struct bt_packet *packet) +{ + return bt_packet_borrow_stream((void *) packet); +} + struct bt_field *bt_packet_borrow_header_field(struct bt_packet *packet) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); return packet->header_field ? packet->header_field->field : NULL; } +const struct bt_field *bt_packet_borrow_header_field_const( + const struct bt_packet *packet) +{ + return bt_packet_borrow_header_field((void *) packet); +} + struct bt_field *bt_packet_borrow_context_field(struct bt_packet *packet) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); return packet->context_field ? packet->context_field->field : NULL; } +const struct bt_field *bt_packet_borrow_context_field_const( + const struct bt_packet *packet) +{ + return bt_packet_borrow_context_field((void *) packet); +} + BT_HIDDEN -void _bt_packet_set_is_frozen(struct bt_packet *packet, bool is_frozen) +void _bt_packet_set_is_frozen(const struct bt_packet *packet, bool is_frozen) { if (!packet) { return; @@ -87,7 +102,7 @@ void _bt_packet_set_is_frozen(struct bt_packet *packet, bool is_frozen) is_frozen); } - packet->frozen = is_frozen; + ((struct bt_packet *) packet)->frozen = is_frozen; } static inline @@ -129,13 +144,13 @@ void reset_packet(struct bt_packet *packet) static void recycle_header_field(struct bt_field_wrapper *header_field, - struct bt_trace *trace) + struct bt_trace_class *tc) { BT_ASSERT(header_field); BT_LIB_LOGD("Recycling packet header field: " - "addr=%p, %![trace-]+t, %![field-]+f", header_field, - trace, header_field->field); - bt_object_pool_recycle_object(&trace->packet_header_field_pool, + "addr=%p, %![tc-]+T, %![field-]+f", header_field, + tc, header_field->field); + bt_object_pool_recycle_object(&tc->packet_header_field_pool, header_field); } @@ -172,7 +187,7 @@ void bt_packet_recycle(struct bt_packet *packet) * 2. Move the stream reference to our `stream` * variable so that we can set the packet's stream member * to NULL before recycling it. We CANNOT do this after - * we put the stream reference because this bt_put() + * we put the stream reference because this bt_object_put_ref() * could destroy the stream, also destroying its * packet pool, thus also destroying our packet object (this * would result in an invalid write access). @@ -198,11 +213,13 @@ void bt_packet_destroy(struct bt_packet *packet) if (packet->stream) { BT_LOGD_STR("Recycling packet's header field."); recycle_header_field(packet->header_field, - bt_stream_class_borrow_trace_inline( + bt_stream_class_borrow_trace_class_inline( packet->stream->class)); } else { bt_field_wrapper_destroy(packet->header_field); } + + packet->header_field = NULL; } if (packet->context_field) { @@ -213,20 +230,24 @@ void bt_packet_destroy(struct bt_packet *packet) } else { bt_field_wrapper_destroy(packet->context_field); } + + packet->context_field = NULL; } if (packet->default_beginning_cv) { BT_LOGD_STR("Recycling beginning clock value."); bt_clock_value_recycle(packet->default_beginning_cv); + packet->default_beginning_cv = NULL; } if (packet->default_end_cv) { BT_LOGD_STR("Recycling end clock value."); bt_clock_value_recycle(packet->default_end_cv); + packet->default_end_cv = NULL; } BT_LOGD_STR("Putting packet's stream."); - bt_put(packet->stream); + BT_OBJECT_PUT_REF_AND_RESET(packet->stream); g_free(packet); } @@ -234,7 +255,7 @@ BT_HIDDEN struct bt_packet *bt_packet_new(struct bt_stream *stream) { struct bt_packet *packet = NULL; - struct bt_trace *trace = NULL; + struct bt_trace_class *trace_class = NULL; BT_ASSERT(stream); BT_LIB_LOGD("Creating packet object: %![stream-]+s", stream); @@ -246,26 +267,27 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream) bt_object_init_shared(&packet->base, (bt_object_release_func) bt_packet_recycle); - packet->stream = bt_get(stream); - trace = bt_stream_class_borrow_trace_inline(stream->class); - BT_ASSERT(trace); + packet->stream = stream; + bt_object_get_no_null_check(stream); + trace_class = bt_stream_class_borrow_trace_class_inline(stream->class); + BT_ASSERT(trace_class); - if (trace->packet_header_ft) { + if (trace_class->packet_header_fc) { BT_LOGD_STR("Creating initial packet header field."); packet->header_field = bt_field_wrapper_create( - &trace->packet_header_field_pool, - trace->packet_header_ft); + &trace_class->packet_header_field_pool, + trace_class->packet_header_fc); if (!packet->header_field) { BT_LOGE_STR("Cannot create packet header field wrapper."); goto error; } } - if (stream->class->packet_context_ft) { + if (stream->class->packet_context_fc) { BT_LOGD_STR("Creating initial packet context field."); packet->context_field = bt_field_wrapper_create( &stream->class->packet_context_field_pool, - stream->class->packet_context_ft); + stream->class->packet_context_fc); if (!packet->context_field) { BT_LOGE_STR("Cannot create packet context field wrapper."); goto error; @@ -297,7 +319,7 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream) goto end; error: - BT_PUT(packet); + BT_OBJECT_PUT_REF_AND_RESET(packet); end: return packet; @@ -322,31 +344,30 @@ struct bt_packet *bt_packet_create(struct bt_stream *stream) } end: - return packet; + return (void *) packet; } int bt_packet_move_header_field(struct bt_packet *packet, struct bt_packet_header_field *header_field) { - struct bt_trace *trace; + struct bt_trace_class *tc; struct bt_field_wrapper *field_wrapper = (void *) header_field; BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field"); BT_ASSERT_PRE_PACKET_HOT(packet); - trace = bt_stream_class_borrow_trace_inline(packet->stream->class); - BT_ASSERT_PRE(trace->packet_header_ft, - "Trace has no packet header field type: %!+t", - trace); - BT_ASSERT_PRE(field_wrapper->field->type == - trace->packet_header_ft, - "Unexpected packet header field's type: " - "%![ft-]+F, %![expected-ft-]+F", field_wrapper->field->type, - trace->packet_header_ft); + tc = bt_stream_class_borrow_trace_class_inline(packet->stream->class); + BT_ASSERT_PRE(tc->packet_header_fc, + "Trace class has no packet header field class: %!+T", tc); + BT_ASSERT_PRE(field_wrapper->field->class == + tc->packet_header_fc, + "Unexpected packet header field's class: " + "%![fc-]+F, %![expected-fc-]+F", field_wrapper->field->class, + tc->packet_header_fc); /* Recycle current header field: always exists */ BT_ASSERT(packet->header_field); - recycle_header_field(packet->header_field, trace); + recycle_header_field(packet->header_field, tc); /* Move new field */ packet->header_field = field_wrapper; @@ -363,14 +384,14 @@ int bt_packet_move_context_field(struct bt_packet *packet, BT_ASSERT_PRE_NON_NULL(field_wrapper, "Context field"); BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet); stream_class = packet->stream->class; - BT_ASSERT_PRE(stream_class->packet_context_ft, - "Stream class has no packet context field type: %!+S", + BT_ASSERT_PRE(stream_class->packet_context_fc, + "Stream class has no packet context field class: %!+S", stream_class); - BT_ASSERT_PRE(field_wrapper->field->type == - stream_class->packet_context_ft, - "Unexpected packet header field's type: " - "%![ft-]+F, %![expected-ft-]+F", field_wrapper->field->type, - stream_class->packet_context_ft); + BT_ASSERT_PRE(field_wrapper->field->class == + stream_class->packet_context_fc, + "Unexpected packet header field's class: " + "%![fc-]+F, %![expected-fc-]+F", field_wrapper->field->class, + stream_class->packet_context_fc); /* Recycle current context field: always exists */ BT_ASSERT(packet->context_field); @@ -381,7 +402,7 @@ int bt_packet_move_context_field(struct bt_packet *packet, return 0; } -int bt_packet_set_default_beginning_clock_value(struct bt_packet *packet, +void bt_packet_set_default_beginning_clock_value(struct bt_packet *packet, uint64_t value_cycles) { struct bt_stream_class *sc; @@ -398,14 +419,15 @@ int bt_packet_set_default_beginning_clock_value(struct bt_packet *packet, "no default beginning clock value: %![packet-]+a, %![sc-]+S", packet, sc); BT_ASSERT(packet->default_beginning_cv); - bt_clock_value_set_value_inline(packet->default_beginning_cv, value_cycles); + bt_clock_value_set_value_inline(packet->default_beginning_cv, + value_cycles); BT_LIB_LOGV("Set packet's default beginning clock value: " - "%![packet-]+a, value=%" PRIu64, value_cycles); - return 0; + "%![packet-]+a, value=%" PRIu64, packet, value_cycles); } enum bt_clock_value_status bt_packet_borrow_default_beginning_clock_value( - struct bt_packet *packet, struct bt_clock_value **clock_value) + const struct bt_packet *packet, + const struct bt_clock_value **clock_value) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)"); @@ -413,7 +435,7 @@ enum bt_clock_value_status bt_packet_borrow_default_beginning_clock_value( return BT_CLOCK_VALUE_STATUS_KNOWN; } -int bt_packet_set_default_end_clock_value(struct bt_packet *packet, +void bt_packet_set_default_end_clock_value(struct bt_packet *packet, uint64_t value_cycles) { struct bt_stream_class *sc; @@ -432,12 +454,12 @@ int bt_packet_set_default_end_clock_value(struct bt_packet *packet, BT_ASSERT(packet->default_end_cv); bt_clock_value_set_value_inline(packet->default_end_cv, value_cycles); BT_LIB_LOGV("Set packet's default end clock value: " - "%![packet-]+a, value=%" PRIu64, value_cycles); - return 0; + "%![packet-]+a, value=%" PRIu64, packet, value_cycles); } enum bt_clock_value_status bt_packet_borrow_default_end_clock_value( - struct bt_packet *packet, struct bt_clock_value **clock_value) + const struct bt_packet *packet, + const struct bt_clock_value **clock_value) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)"); @@ -446,7 +468,7 @@ enum bt_clock_value_status bt_packet_borrow_default_end_clock_value( } enum bt_property_availability bt_packet_get_discarded_event_counter_snapshot( - struct bt_packet *packet, uint64_t *value) + const struct bt_packet *packet, uint64_t *value) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(value, "Value (output)"); @@ -454,7 +476,7 @@ enum bt_property_availability bt_packet_get_discarded_event_counter_snapshot( return packet->discarded_event_counter_snapshot.base.avail; } -int bt_packet_set_discarded_event_counter_snapshot(struct bt_packet *packet, +void bt_packet_set_discarded_event_counter_snapshot(struct bt_packet *packet, uint64_t value) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); @@ -463,11 +485,10 @@ int bt_packet_set_discarded_event_counter_snapshot(struct bt_packet *packet, "Packet's stream's discarded event counter is not enabled: " "%![packet-]+a", packet); bt_property_uint_set(&packet->discarded_event_counter_snapshot, value); - return 0; } enum bt_property_availability bt_packet_get_packet_counter_snapshot( - struct bt_packet *packet, uint64_t *value) + const struct bt_packet *packet, uint64_t *value) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(value, "Value (output)"); @@ -475,7 +496,7 @@ enum bt_property_availability bt_packet_get_packet_counter_snapshot( return packet->packet_counter_snapshot.base.avail; } -int bt_packet_set_packet_counter_snapshot(struct bt_packet *packet, +void bt_packet_set_packet_counter_snapshot(struct bt_packet *packet, uint64_t value) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); @@ -484,5 +505,4 @@ int bt_packet_set_packet_counter_snapshot(struct bt_packet *packet, "Packet's stream's packet counter is not enabled: " "%![packet-]+a", packet); bt_property_uint_set(&packet->packet_counter_snapshot, value); - return 0; }