X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fnotification%2Fpacket.c;h=acf0ce5f1b8eb2b5235445f7eb4479cb6121c62d;hb=65300d60e4b4f167e5fc8f584677757ce09a3844;hp=d0286eecb212b9aefec856890aca8f4c07f6b6fb;hpb=9d408fcae74602e3591f66623ceb85f482d948ed;p=babeltrace.git diff --git a/lib/graph/notification/packet.c b/lib/graph/notification/packet.c index d0286eec..acf0ce5f 100644 --- a/lib/graph/notification/packet.c +++ b/lib/graph/notification/packet.c @@ -28,182 +28,256 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include #include -static -void bt_notification_packet_begin_destroy(struct bt_object *obj) +BT_HIDDEN +struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph) { - struct bt_notification_packet_begin *notification = - (struct bt_notification_packet_begin *) obj; + struct bt_notification_packet_begin *notification; - BT_LOGD("Destroying packet beginning notification: addr=%p", - notification); - BT_LOGD_STR("Putting packet."); - BT_PUT(notification->packet); - g_free(notification); -} + notification = g_new0(struct bt_notification_packet_begin, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one packet beginning notification."); + goto error; + } -static -void bt_notification_packet_end_destroy(struct bt_object *obj) -{ - struct bt_notification_packet_end *notification = - (struct bt_notification_packet_end *) obj; + bt_notification_init(¬ification->parent, + BT_NOTIFICATION_TYPE_PACKET_BEGIN, + (bt_object_release_func) bt_notification_packet_begin_recycle, + graph); + goto end; - BT_LOGD("Destroying packet end notification: addr=%p", - notification); - BT_LOGD_STR("Putting packet."); - BT_PUT(notification->packet); - g_free(notification); +error: + BT_OBJECT_PUT_REF_AND_RESET(notification); + +end: + return (void *) notification; } struct bt_notification *bt_notification_packet_begin_create( - struct bt_ctf_packet *packet) + struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_packet *packet) { - struct bt_notification_packet_begin *notification; - struct bt_ctf_stream *stream; - struct bt_ctf_stream_class *stream_class; + struct bt_notification_packet_begin *notification = NULL; + struct bt_stream *stream; + struct bt_stream_class *stream_class; + struct bt_graph *graph; - if (!packet) { - BT_LOGW_STR("Invalid parameter: packet is NULL."); - goto error; - } - - stream = bt_ctf_packet_borrow_stream(packet); - assert(stream); - stream_class = bt_ctf_stream_borrow_stream_class(stream); - assert(stream_class); + BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + stream = bt_packet_borrow_stream(packet); + BT_ASSERT(stream); + stream_class = bt_stream_borrow_class(stream); + BT_ASSERT(stream_class); BT_LOGD("Creating packet beginning notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " "stream-class-id=%" PRId64, - packet, stream, bt_ctf_stream_get_name(stream), + packet, stream, bt_stream_get_name(stream), stream_class, - bt_ctf_stream_class_get_name(stream_class), - bt_ctf_stream_class_get_id(stream_class)); - notification = g_new0(struct bt_notification_packet_begin, 1); + bt_stream_class_get_name(stream_class), + bt_stream_class_get_id(stream_class)); + graph = bt_private_connection_private_notification_iterator_borrow_graph( + notif_iter); + notification = (void *) bt_notification_create_from_pool( + &graph->packet_begin_notif_pool, graph); if (!notification) { - BT_LOGE_STR("Failed to allocate one packet beginning notification."); - goto error; + /* bt_notification_create_from_pool() logs errors */ + goto end; } - bt_notification_init(¬ification->parent, - BT_NOTIFICATION_TYPE_PACKET_BEGIN, - bt_notification_packet_begin_destroy); - notification->packet = bt_get(packet); + BT_ASSERT(!notification->packet); + notification->packet = packet; + bt_object_get_no_null_check_no_parent_check( + ¬ification->packet->base); + bt_packet_set_is_frozen(packet, true); BT_LOGD("Created packet beginning notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " "stream-class-id=%" PRId64 ", addr=%p", - packet, stream, bt_ctf_stream_get_name(stream), + packet, stream, bt_stream_get_name(stream), stream_class, - bt_ctf_stream_class_get_name(stream_class), - bt_ctf_stream_class_get_id(stream_class), notification); - return ¬ification->parent; -error: - return NULL; + bt_stream_class_get_name(stream_class), + bt_stream_class_get_id(stream_class), notification); + goto end; + +end: + return (void *) notification; } -struct bt_ctf_packet *bt_notification_packet_begin_get_packet( - struct bt_notification *notification) +BT_HIDDEN +void bt_notification_packet_begin_destroy(struct bt_notification *notif) { - struct bt_ctf_packet *ret = NULL; - struct bt_notification_packet_begin *packet_begin; + struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } + BT_LOGD("Destroying packet beginning notification: addr=%p", notif); + BT_LOGD_STR("Putting packet."); + BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet); + g_free(notif); +} - if (notification->type != BT_NOTIFICATION_TYPE_PACKET_BEGIN) { - BT_LOGW("Invalid parameter: notification is not a packet beginning notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; +BT_HIDDEN +void bt_notification_packet_begin_recycle(struct bt_notification *notif) +{ + struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; + struct bt_graph *graph; + + BT_ASSERT(packet_begin_notif); + + if (unlikely(!notif->graph)) { + bt_notification_packet_begin_destroy(notif); + return; } + BT_LOGD("Recycling packet beginning notification: addr=%p", notif); + bt_notification_reset(notif); + bt_object_put_no_null_check(&packet_begin_notif->packet->base); + packet_begin_notif->packet = NULL; + graph = notif->graph; + notif->graph = NULL; + bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif); +} + +struct bt_packet *bt_notification_packet_begin_borrow_packet( + struct bt_notification *notification) +{ + struct bt_notification_packet_begin *packet_begin; + + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_PACKET_BEGIN); packet_begin = container_of(notification, struct bt_notification_packet_begin, parent); - ret = bt_get(packet_begin->packet); -end: - return ret; + return packet_begin->packet; } -struct bt_notification *bt_notification_packet_end_create( - struct bt_ctf_packet *packet) +BT_HIDDEN +struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) { struct bt_notification_packet_end *notification; - struct bt_ctf_stream *stream; - struct bt_ctf_stream_class *stream_class; - if (!packet) { - BT_LOGW_STR("Invalid parameter: packet is NULL."); + notification = g_new0(struct bt_notification_packet_end, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one packet end notification."); goto error; } - stream = bt_ctf_packet_borrow_stream(packet); - assert(stream); - stream_class = bt_ctf_stream_borrow_stream_class(stream); - assert(stream_class); + bt_notification_init(¬ification->parent, + BT_NOTIFICATION_TYPE_PACKET_END, + (bt_object_release_func) bt_notification_packet_end_recycle, + graph); + goto end; + +error: + BT_OBJECT_PUT_REF_AND_RESET(notification); + +end: + return (void *) notification; +} + +struct bt_notification *bt_notification_packet_end_create( + struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_packet *packet) +{ + struct bt_notification_packet_end *notification = NULL; + struct bt_stream *stream; + struct bt_stream_class *stream_class; + struct bt_graph *graph; + + BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + stream = bt_packet_borrow_stream(packet); + BT_ASSERT(stream); + stream_class = bt_stream_borrow_class(stream); + BT_ASSERT(stream_class); BT_LOGD("Creating packet end notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " "stream-class-id=%" PRId64, - packet, stream, bt_ctf_stream_get_name(stream), + packet, stream, bt_stream_get_name(stream), stream_class, - bt_ctf_stream_class_get_name(stream_class), - bt_ctf_stream_class_get_id(stream_class)); - notification = g_new0(struct bt_notification_packet_end, 1); + bt_stream_class_get_name(stream_class), + bt_stream_class_get_id(stream_class)); + graph = bt_private_connection_private_notification_iterator_borrow_graph( + notif_iter); + notification = (void *) bt_notification_create_from_pool( + &graph->packet_end_notif_pool, graph); if (!notification) { - BT_LOGE_STR("Failed to allocate one packet end notification."); - goto error; + /* bt_notification_create_from_pool() logs errors */ + goto end; } - bt_notification_init(¬ification->parent, - BT_NOTIFICATION_TYPE_PACKET_END, - bt_notification_packet_end_destroy); - notification->packet = bt_get(packet); + BT_ASSERT(!notification->packet); + notification->packet = packet; + bt_object_get_no_null_check_no_parent_check( + ¬ification->packet->base); + bt_packet_set_is_frozen(packet, true); BT_LOGD("Created packet end notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " "stream-class-id=%" PRId64 ", addr=%p", - packet, stream, bt_ctf_stream_get_name(stream), + packet, stream, bt_stream_get_name(stream), stream_class, - bt_ctf_stream_class_get_name(stream_class), - bt_ctf_stream_class_get_id(stream_class), notification); - return ¬ification->parent; -error: - return NULL; + bt_stream_class_get_name(stream_class), + bt_stream_class_get_id(stream_class), notification); + goto end; + +end: + return (void *) notification; } -struct bt_ctf_packet *bt_notification_packet_end_get_packet( - struct bt_notification *notification) +BT_HIDDEN +void bt_notification_packet_end_destroy(struct bt_notification *notif) { - struct bt_ctf_packet *ret = NULL; - struct bt_notification_packet_end *packet_end; + struct bt_notification_packet_end *packet_end_notif = (void *) notif; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } + BT_LOGD("Destroying packet end notification: addr=%p", notif); + BT_LOGD_STR("Putting packet."); + BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); + g_free(notif); +} - if (notification->type != BT_NOTIFICATION_TYPE_PACKET_END) { - BT_LOGW("Invalid parameter: notification is not a packet end notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; +BT_HIDDEN +void bt_notification_packet_end_recycle(struct bt_notification *notif) +{ + struct bt_notification_packet_end *packet_end_notif = (void *) notif; + struct bt_graph *graph; + + BT_ASSERT(packet_end_notif); + + if (!notif->graph) { + bt_notification_packet_end_destroy(notif); + return; } + BT_LOGD("Recycling packet end notification: addr=%p", notif); + bt_notification_reset(notif); + BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); + graph = notif->graph; + notif->graph = NULL; + bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); +} + +struct bt_packet *bt_notification_packet_end_borrow_packet( + struct bt_notification *notification) +{ + struct bt_notification_packet_end *packet_end; + + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_PACKET_END); packet_end = container_of(notification, struct bt_notification_packet_end, parent); - ret = bt_get(packet_end->packet); -end: - return ret; + return packet_end->packet; }