X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fnotification%2Fevent.c;h=3ed1c4cd0f6b6d351619bbdcd2497755c72d4c8b;hb=5c5632787fc9cafa602c89a28966bcfd01ec0204;hp=486a8b1018eb248780b3de2979ba75cc76f05ea2;hpb=312c056ae3d374b253fa0cfe5ed576c0b0e5e569;p=babeltrace.git diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index 486a8b10..3ed1c4cd 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -42,21 +43,6 @@ #include #include -static -void bt_notification_event_destroy(struct bt_object *obj) -{ - struct bt_notification_event *notification = - (struct bt_notification_event *) obj; - - BT_LOGD("Destroying event notification: addr=%p", notification); - BT_LOGD_STR("Recycling event."); - bt_event_recycle(notification->event); - notification->event = NULL; - BT_LOGD_STR("Putting clock class priority map."); - BT_PUT(notification->cc_prio_map); - g_free(notification); -} - BT_ASSERT_PRE_FUNC static inline bool event_class_has_trace(struct bt_event_class *event_class) { @@ -67,7 +53,30 @@ static inline bool event_class_has_trace(struct bt_event_class *event_class) return bt_stream_class_borrow_trace(stream_class) != NULL; } +BT_HIDDEN +struct bt_notification *bt_notification_event_new(struct bt_graph *graph) +{ + struct bt_notification_event *notification = NULL; + + notification = g_new0(struct bt_notification_event, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one event notification."); + goto error; + } + + bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, + (bt_object_release_func) bt_notification_event_recycle, graph); + goto end; + +error: + BT_PUT(notification); + +end: + return (void *) notification; +} + struct bt_notification *bt_notification_event_create( + struct bt_graph *graph, struct bt_event_class *event_class, struct bt_packet *packet, struct bt_clock_class_priority_map *cc_prio_map) @@ -99,14 +108,13 @@ struct bt_notification *bt_notification_event_create( BT_ASSERT_PRE(event_class_has_trace(event_class), "Event class is not part of a trace: %!+E", event_class); - notification = g_new0(struct bt_notification_event, 1); + notification = (void *) bt_notification_create_from_pool( + &graph->event_notif_pool, graph); if (!notification) { - BT_LOGE_STR("Failed to allocate one event notification."); + /* bt_notification_create_from_pool() logs errors */ goto error; } - bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, - bt_notification_event_destroy); notification->event = bt_event_create(event_class, packet); if (!notification->event) { BT_LIB_LOGE("Cannot create event from event class: " @@ -132,7 +140,52 @@ error: end: bt_put(cc_prio_map); - return ¬ification->parent; + return (void *) notification; +} + +BT_HIDDEN +void bt_notification_event_destroy(struct bt_notification *notif) +{ + struct bt_notification_event *event_notif = (void *) notif; + + BT_LOGD("Destroying event notification: addr=%p", notif); + + if (event_notif->event) { + BT_LOGD_STR("Recycling event."); + bt_event_recycle(event_notif->event); + } + + BT_LOGD_STR("Putting clock class priority map."); + BT_PUT(event_notif->cc_prio_map); + g_free(notif); +} + +BT_HIDDEN +void bt_notification_event_recycle(struct bt_notification *notif) +{ + struct bt_notification_event *event_notif = (void *) notif; + struct bt_graph *graph; + + BT_ASSERT(event_notif); + + if (!notif->graph) { + bt_notification_event_destroy(notif); + return; + } + + BT_LOGD("Recycling event notification: addr=%p", notif); + bt_notification_reset(notif); + + if (event_notif->event) { + BT_LOGD_STR("Recycling event."); + bt_event_recycle(event_notif->event); + event_notif->event = NULL; + } + + BT_PUT(event_notif->cc_prio_map); + graph = notif->graph; + notif->graph = NULL; + bt_object_pool_recycle_object(&graph->event_notif_pool, notif); } struct bt_event *bt_notification_event_borrow_event(