lib: use object pool for event and packet notifications
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 4 Jun 2018 21:00:10 +0000 (17:00 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:05:45 +0000 (00:05 -0400)
This patch adds object pooling for event, packet beginning, and packet
end notifications.

The object pools are located in graph objects: there is one for each
notification type. All the notification creation functions (in case we
want to recycle other types of notification objects in the future) take
a graph object so that a notification recycling function can find the
appropriate object pool. I'm adding the convenient
bt_private_connection_private_notification_iterator_borrow_graph()
function for a notification iterator user function to borrow its graph
easily.

If the notification has a reference to its "creating" graph, there's a
possible reference cycle, for example:

* Graph -> connection -> notification iterator -> notification -> graph
* Graph -> component -> notification -> graph

To avoid this, the notification's graph link is weak, and the
notification creation function adds the notification to the graph's
array of notifications (also weak). While the graph is alive,
notification recycling functions are free to use the appropriate graph's
pool. When the graph is destroyed, all the notifications which have a
link to it are notified so that they "unlink" the graph. In this case,
notification recycling functions destroy the notification instead of
recycling it.

Some `bt_X_from_private()` functions are renamed to
`bt_X_borrow_from_private()` and do not return a new reference to make
it clearer.

Everything related to the notification heap API is removed because it is
not used anywhere and not needed since the `flt.utils.muxer` component
class does this.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
56 files changed:
include/Makefile.am
include/babeltrace/babeltrace.h
include/babeltrace/graph/component-internal.h
include/babeltrace/graph/component.h
include/babeltrace/graph/connection-internal.h
include/babeltrace/graph/graph-internal.h
include/babeltrace/graph/graph.h
include/babeltrace/graph/notification-discarded-elements-internal.h
include/babeltrace/graph/notification-event-internal.h
include/babeltrace/graph/notification-event.h
include/babeltrace/graph/notification-heap-internal.h [deleted file]
include/babeltrace/graph/notification-heap.h [deleted file]
include/babeltrace/graph/notification-inactivity.h
include/babeltrace/graph/notification-internal.h
include/babeltrace/graph/notification-iterator-internal.h
include/babeltrace/graph/notification-packet-internal.h
include/babeltrace/graph/notification-packet.h
include/babeltrace/graph/notification-stream.h
include/babeltrace/graph/port-internal.h
include/babeltrace/graph/private-component.h
include/babeltrace/graph/private-connection-private-notification-iterator.h
include/babeltrace/graph/private-connection.h
include/babeltrace/graph/private-port.h
lib/ctf-ir/stream-class.c
lib/graph/component.c
lib/graph/connection.c
lib/graph/filter.c
lib/graph/graph.c
lib/graph/iterator.c
lib/graph/notification/Makefile.am
lib/graph/notification/discarded-elements.c
lib/graph/notification/event.c
lib/graph/notification/heap.c [deleted file]
lib/graph/notification/inactivity.c
lib/graph/notification/notification.c
lib/graph/notification/packet.c
lib/graph/notification/stream.c
lib/graph/port.c
lib/graph/sink.c
lib/graph/source.c
lib/lib-logging.c
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/common/notif-iter/notif-iter.h
plugins/ctf/fs-src/data-stream-file.c
plugins/ctf/fs-src/data-stream-file.h
plugins/ctf/fs-src/fs.c
plugins/ctf/fs-src/fs.h
plugins/ctf/fs-src/query.c
plugins/text/dmesg/dmesg.c
plugins/utils/muxer/muxer.c
tests/Makefile.am
tests/lib/Makefile.am
tests/lib/test_bt_notification_heap.c [deleted file]
tests/lib/test_bt_notification_iterator.c
tests/lib/test_graph_topo.c
tests/plugins/test-utils-muxer.c

index acadd59f6a337238072c5759d578e6b131b967cf..b25aabfef96b2f6437f9c1eecd4334e00157a9e1 100644 (file)
@@ -143,7 +143,6 @@ babeltracegraphinclude_HEADERS = \
        babeltrace/graph/notification-discarded-events.h \
        babeltrace/graph/notification-discarded-packets.h \
        babeltrace/graph/notification-event.h \
-       babeltrace/graph/notification-heap.h \
        babeltrace/graph/notification-inactivity.h \
        babeltrace/graph/notification-iterator.h \
        babeltrace/graph/notification-packet.h \
@@ -229,7 +228,6 @@ noinst_HEADERS = \
        babeltrace/graph/graph-internal.h \
        babeltrace/graph/component-class-sink-colander-internal.h \
        babeltrace/graph/notification-inactivity-internal.h \
-       babeltrace/graph/notification-heap-internal.h \
        babeltrace/graph/component-source-internal.h \
        babeltrace/graph/notification-discarded-elements-internal.h \
        babeltrace/graph/notification-packet-internal.h \
index cd910280777577f8f879f35c0f8f1b6ce6c79124..181c01413aa4398e26aa879f7b1519a9618c422b 100644 (file)
@@ -87,7 +87,6 @@
 #include <babeltrace/graph/notification-discarded-events.h>
 #include <babeltrace/graph/notification-discarded-packets.h>
 #include <babeltrace/graph/notification-event.h>
-#include <babeltrace/graph/notification-heap.h>
 #include <babeltrace/graph/notification-inactivity.h>
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/notification-packet.h>
index f742c7b1717f692bf6dcaca032e0083a2acdfe09..65f5e4d82bac46e1fded9cf378f7e17078d8ea7c 100644 (file)
@@ -69,13 +69,6 @@ struct bt_component {
        bool initialized;
 };
 
-static inline
-struct bt_component *bt_component_borrow_from_private(
-               struct bt_private_component *private_component)
-{
-       return (void *) private_component;
-}
-
 static inline
 struct bt_private_component *bt_private_component_from_component(
                struct bt_component *component)
@@ -83,13 +76,6 @@ struct bt_private_component *bt_private_component_from_component(
        return (void *) component;
 }
 
-static inline
-struct bt_graph *bt_component_borrow_graph(struct bt_component *comp)
-{
-       BT_ASSERT(comp);
-       return (void *) comp->base.parent;
-}
-
 BT_HIDDEN
 enum bt_component_status bt_component_create(
                struct bt_component_class *component_class,
index 7423e92a5fa3861c83360e7316adbd8187a84597..f2db9d723c1f254056937b90e1be920fe016429f 100644 (file)
@@ -33,6 +33,9 @@
 /* For bt_bool */
 #include <babeltrace/types.h>
 
+/* For bt_get */
+#include <babeltrace/ref.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -84,7 +87,13 @@ bt_bool bt_component_is_sink(struct bt_component *component)
                BT_COMPONENT_CLASS_TYPE_SINK;
 }
 
-extern struct bt_graph *bt_component_get_graph(struct bt_component *component);
+extern struct bt_graph *bt_component_borrow_graph(struct bt_component *component);
+
+static inline
+struct bt_graph *bt_component_get_graph(struct bt_component *component)
+{
+       return bt_get(bt_component_borrow_graph(component));
+}
 
 #ifdef __cplusplus
 }
index 366dc0e4e8babc81ed854fdcfc76f9065689af15..c1eea4b18a25f71004fcb4f5e5b33f60c9886677 100644 (file)
@@ -60,13 +60,6 @@ struct bt_connection {
        GPtrArray *iterators;
 };
 
-static inline
-struct bt_connection *bt_connection_borrow_from_private(
-               struct bt_private_connection *private_connection)
-{
-       return (void *) private_connection;
-}
-
 static inline
 struct bt_private_connection *bt_private_connection_from_connection(
                struct bt_connection *connection)
index cd1b557d946a9287a705abf333a5fe454397f2c1..9e6012ec641e18225640869a8429db2205ec15fd 100644 (file)
 
 #include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/component-status.h>
+#include <babeltrace/graph/notification.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/object-internal.h>
+#include <babeltrace/object-pool-internal.h>
 #include <babeltrace/assert-internal.h>
 #include <stdlib.h>
 #include <glib.h>
@@ -80,6 +82,31 @@ struct bt_graph {
                GArray *ports_connected;
                GArray *ports_disconnected;
        } listeners;
+
+       /* Pool of `struct bt_notification_event *` */
+       struct bt_object_pool event_notif_pool;
+
+       /* Pool of `struct bt_notification_packet_begin *` */
+       struct bt_object_pool packet_begin_notif_pool;
+
+       /* Pool of `struct bt_notification_packet_end *` */
+       struct bt_object_pool packet_end_notif_pool;
+
+       /*
+        * Array of `struct bt_notification *` (weak).
+        *
+        * This is an array of all the notifications ever created from
+        * this graph. Some of them can be in one of the pools above,
+        * some of them can be at large. Because each notification has a
+        * weak pointer to the graph containing its pool, we need to
+        * notify each notification that the graph is gone on graph
+        * destruction.
+        *
+        * TODO: When we support a maximum size for object pools,
+        * add a way for a notification to remove itself from this
+        * array (on destruction).
+        */
+       GPtrArray *notifications;
 };
 
 static inline
@@ -130,6 +157,10 @@ BT_HIDDEN
 int bt_graph_remove_unconnected_component(struct bt_graph *graph,
                struct bt_component *component);
 
+BT_HIDDEN
+void bt_graph_add_notification(struct bt_graph *graph,
+               struct bt_notification *notif);
+
 static inline
 const char *bt_graph_status_string(enum bt_graph_status status)
 {
index bb3d84cbd1322daca2686185b1723890c55ddb18..acff83931a8b1a069f1b2e110bc58715ea9cf14e 100644 (file)
@@ -38,6 +38,7 @@ struct bt_port;
 struct bt_connection;
 struct bt_component;
 struct bt_component_class;
+struct bt_value;
 
 enum bt_graph_status {
        BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION = 111,
index 489a0464d03b14c5893391cce90280b41472c97f..c5d1f0eaa5a9b52438ca8786fa4cff5eb97e2fe5 100644 (file)
@@ -43,6 +43,7 @@ struct bt_notification_discarded_elements {
 
 BT_HIDDEN
 struct bt_notification *bt_notification_discarded_elements_create(
+               struct bt_graph *graph,
                enum bt_notification_type type,
                struct bt_stream *stream,
                struct bt_clock_value *begin_clock_value,
index a5dea56ff60c7cb0811eb0d3aaab2d0c58a4ee37..436477b3b85bd50456e3a9c94ef68a8f91052c29 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <babeltrace/compiler-internal.h>
+#include <babeltrace/ctf-ir/event-class.h>
 #include <babeltrace/ctf-ir/event.h>
 #include <babeltrace/graph/notification-internal.h>
 #include <babeltrace/graph/clock-class-priority-map.h>
@@ -43,6 +44,15 @@ struct bt_notification_event {
        struct bt_clock_class_priority_map *cc_prio_map;
 };
 
+BT_HIDDEN
+struct bt_notification *bt_notification_event_new(struct bt_graph *graph);
+
+BT_HIDDEN
+void bt_notification_event_recycle(struct bt_notification *notif);
+
+BT_HIDDEN
+void bt_notification_event_destroy(struct bt_notification *notif);
+
 #ifdef __cplusplus
 }
 #endif
index d6614fb6ad5dec10b0dc196c77e311281094974c..ab8a66066bf8bbf0b6b110b7da4f81b4558bc1a6 100644 (file)
@@ -39,7 +39,8 @@ struct bt_event;
 struct bt_event_class;
 struct bt_clock_class_priority_map;
 
-extern struct bt_notification *bt_notification_event_create(
+extern
+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 *clock_class_priority_map);
diff --git a/include/babeltrace/graph/notification-heap-internal.h b/include/babeltrace/graph/notification-heap-internal.h
deleted file mode 100644 (file)
index a93c5fb..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef BABELTRACE_GRAPH_NOTIFICATION_HEAP_INTERNAL_H
-#define BABELTRACE_GRAPH_NOTIFICATION_HEAP_INTERNAL_H
-
-/*
- * Babeltrace - CTF notification heap priority heap
- *
- * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * 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.
- */
-
-#include <babeltrace/object-internal.h>
-#include <babeltrace/graph/notification-heap.h>
-#include <babeltrace/graph/notification.h>
-#include <glib.h>
-
-struct bt_notification_heap {
-       struct bt_object base;
-       GPtrArray *ptrs;
-       size_t count;
-       bt_notification_time_compare_func compare;
-       void *compare_data;
-};
-
-#endif /* BABELTRACE_GRAPH_NOTIFICATION_HEAP_INTERNAL_H */
diff --git a/include/babeltrace/graph/notification-heap.h b/include/babeltrace/graph/notification-heap.h
deleted file mode 100644 (file)
index 3efb541..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-#ifndef BABELTRACE_GRAPH_NOTIFICATION_HEAP_H
-#define BABELTRACE_GRAPH_NOTIFICATION_HEAP_H
-
-/*
- * Babeltrace - Notification Heap
- *
- * Copyright (c) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * 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.
- */
-
-#include <stddef.h>
-
-/* For bt_bool */
-#include <babeltrace/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct bt_notification;
-
-/**
- * bt_notification_time_compare - Compare two notifications' timestamps
- *
- * Compare two notifications in the time domain. Return true if 'a' happened
- * prior to 'b'. In the case where both notifications are deemed to have
- * happened at the same time, an implementation-defined critarion shall be
- * used to order the notifications. This criterion shall ensure a consistent
- * ordering over multiple runs.
- */
-typedef bt_bool (*bt_notification_time_compare_func)(
-               struct bt_notification *a, struct bt_notification *b,
-               void *user_data);
-
-/**
- * bt_notification_heap_create - create a new bt_notification heap.
- *
- * @comparator: Function to use for notification comparisons.
- *
- * Returns a new notification heap, NULL on error.
- */
-extern struct bt_notification_heap *bt_notification_heap_create(
-               bt_notification_time_compare_func comparator, void *user_data);
-
-/**
- * bt_notification_heap_insert - insert an element into the heap
- *
- * @heap: the heap to be operated on
- * @notification: the notification to add
- *
- * Insert a notification into the heap.
- *
- * Returns 0 on success, a negative value on error.
- */
-extern int bt_notification_heap_insert(struct bt_notification_heap *heap,
-               struct bt_notification *notification);
-
-/**
- * bt_notification_heap_peek - return the element on top of the heap.
- *
- * @heap: the heap to be operated on
- *
- * Returns the top element of the heap, without performing any modification
- * to the heap structure. Returns NULL if the heap is empty. The returned
- * notification must be bt_put() by the caller.
- */
-extern struct bt_notification *bt_notification_heap_peek(
-               struct bt_notification_heap *heap);
-
-/**
- * bt_notification_heap_pop - remove the element sitting on top of the heap.
- * @heap: the heap to be operated on
- *
- * Returns the top element of the heap. The element is removed from the
- * heap. Returns NULL if the heap is empty. The returned notification must be
- * bt_put() by the caller.
- */
-extern struct bt_notification *bt_notification_heap_pop(
-               struct bt_notification_heap *heap);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BABELTRACE_GRAPH_NOTIFICATION_HEAP_H */
index 93be8b1243c73903feeba34abda7530fb8a9d431..c530660c013d43ba7b79f3f20ae36dc4220c6393 100644 (file)
@@ -34,7 +34,9 @@ struct bt_notification;
 struct bt_clock_class_priority_map;
 struct bt_clock_class;
 
-extern struct bt_notification *bt_notification_inactivity_create(
+extern
+struct bt_notification *bt_notification_inactivity_create(
+               struct bt_graph *graph,
                struct bt_clock_class_priority_map *clock_class_priority_map);
 
 extern struct bt_clock_class_priority_map *
index 2fbdbb42cbc1ab38a0ec7c2f259b44756027f2a1..3cd905097907691cba25a26e75a9ecc10fcb8e7c 100644 (file)
 #include <babeltrace/ref-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/object-internal.h>
+#include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/notification.h>
 #include <babeltrace/ctf-ir/stream.h>
+#include <babeltrace/object-pool-internal.h>
 #include <babeltrace/types.h>
 
 typedef struct bt_stream *(*get_stream_func)(
@@ -40,9 +42,11 @@ typedef struct bt_stream *(*get_stream_func)(
 struct bt_notification {
        struct bt_object base;
        enum bt_notification_type type;
-       get_stream_func get_stream;
        uint64_t seq_num;
        bt_bool frozen;
+
+       /* Owned by this; keeps the graph alive while the notif. is alive */
+       struct bt_graph *graph;
 };
 
 #define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type)                     \
@@ -54,13 +58,61 @@ struct bt_notification {
 BT_HIDDEN
 void bt_notification_init(struct bt_notification *notification,
                enum bt_notification_type type,
-               bt_object_release_func release);
+               bt_object_release_func release,
+               struct bt_graph *graph);
+
+static inline
+void bt_notification_reset(struct bt_notification *notification)
+{
+       BT_ASSERT(notification);
+
+#ifdef BT_DEV_MODE
+       notification->frozen = BT_FALSE;
+       notification->seq_num = UINT64_C(-1);
+#endif
+}
+
+static inline
+struct bt_notification *bt_notification_create_from_pool(
+               struct bt_object_pool *pool, struct bt_graph *graph)
+{
+       struct bt_notification *notif = bt_object_pool_create_object(pool);
+
+       if (!notif) {
+#ifdef BT_LIB_LOGE
+               BT_LIB_LOGE("Cannot allocate one notification from notification pool: "
+                       "%![pool-]+o, %![graph-]+g", pool, graph);
+#endif
+               goto error;
+       }
+
+       if (!notif->graph) {
+               notif->graph = graph;
+       }
+
+       goto end;
+
+error:
+       BT_PUT(notif);
 
-static inline void bt_notification_freeze(struct bt_notification *notification)
+end:
+       return notif;
+}
+
+static inline void _bt_notification_freeze(struct bt_notification *notification)
 {
        notification->frozen = BT_TRUE;
 }
 
+BT_HIDDEN
+void bt_notification_unlink_graph(struct bt_notification *notif);
+
+#ifdef BT_DEV_MODE
+# define bt_notification_freeze                _bt_notification_freeze
+#else
+# define bt_notification_freeze(_x)
+#endif /* BT_DEV_MODE */
+
 static inline
 const char *bt_notification_type_string(enum bt_notification_type type)
 {
index 55aa4e6210d09942c493d62ec9524b60aec1960c..2d2ef9cabf08eacccf91e980c633fb209aa4a226 100644 (file)
@@ -95,6 +95,7 @@ struct bt_notification_iterator_private_connection {
        struct bt_component *upstream_component; /* Weak */
        struct bt_port *upstream_port; /* Weak */
        struct bt_connection *connection; /* Weak */
+       struct bt_graph *graph; /* Weak */
 
        /*
         * This hash table keeps the state of a stream as viewed by
@@ -145,14 +146,6 @@ void bt_notification_iterator_replace_current_notification(
        iterator->current_notification = bt_get(notification);
 }
 
-static inline
-struct bt_notification_iterator_private_connection *
-bt_private_connection_notification_iterator_borrow_from_private(
-               struct bt_private_connection_private_notification_iterator *private_notification_iterator)
-{
-       return (void *) private_notification_iterator;
-}
-
 static inline
 struct bt_private_connection_private_notification_iterator *
 bt_private_connection_private_notification_iterator_from_notification_iterator(
index 467d08615092c7afa7edcb26641eb53b7b38dcfe..639925b43add25018974a2bdc5e9f1420e1ad784 100644 (file)
@@ -42,4 +42,22 @@ struct bt_notification_packet_end {
        struct bt_packet *packet;
 };
 
+BT_HIDDEN
+struct bt_notification *bt_notification_packet_begin_new(
+               struct bt_graph *graph);
+BT_HIDDEN
+void bt_notification_packet_begin_recycle(struct bt_notification *notif);
+
+BT_HIDDEN
+void bt_notification_packet_begin_destroy(struct bt_notification *notif);
+
+BT_HIDDEN
+struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph);
+
+BT_HIDDEN
+void bt_notification_packet_end_recycle(struct bt_notification *notif);
+
+BT_HIDDEN
+void bt_notification_packet_end_destroy(struct bt_notification *notif);
+
 #endif /* BABELTRACE_GRAPH_NOTIFICATION_PACKET_INTERNAL_H */
index 6b237c3b2e93fa1eef2083022212652198e6d334..e3c9d55b401e094c5d575497b69a157c050d932c 100644 (file)
@@ -37,11 +37,14 @@ extern "C" {
 struct bt_notification;
 struct bt_packet;
 
-extern struct bt_notification *bt_notification_packet_begin_create(
-               struct bt_packet *packet);
+extern
+struct bt_notification *bt_notification_packet_begin_create(
+               struct bt_graph *graph, struct bt_packet *packet);
+
+extern
+struct bt_notification *bt_notification_packet_end_create(
+               struct bt_graph *graph, struct bt_packet *packet);
 
-extern struct bt_notification *bt_notification_packet_end_create(
-               struct bt_packet *packet);
 
 extern struct bt_packet *bt_notification_packet_begin_borrow_packet(
                struct bt_notification *notification);
index 5deff05b74a15e4b0ae67ed72dc9b198898d6a77..e016117ae9c2691ee5955b4f264b2767f9d76c47 100644 (file)
@@ -37,10 +37,14 @@ extern "C" {
 struct bt_notification;
 struct bt_stream;
 
-extern struct bt_notification *bt_notification_stream_begin_create(
+extern
+struct bt_notification *bt_notification_stream_begin_create(
+               struct bt_graph *graph,
                struct bt_stream *stream);
 
-extern struct bt_notification *bt_notification_stream_end_create(
+extern
+struct bt_notification *bt_notification_stream_end_create(
+               struct bt_graph *graph,
                struct bt_stream *stream);
 
 extern struct bt_stream *bt_notification_stream_begin_borrow_stream(
index 8f2fb4b7942c147c59709832203802f4d02bdab4..57f817ee5f5cc2008a3162f2a2c1599b087143fb 100644 (file)
@@ -37,13 +37,6 @@ struct bt_port {
        void *user_data;
 };
 
-static inline
-struct bt_port *bt_port_borrow_from_private(
-               struct bt_private_port *private_port)
-{
-       return (void *) private_port;
-}
-
 static inline
 struct bt_private_port *bt_private_port_from_port(
                struct bt_port *port)
index ce0a6b062d1719217dcd25dca137e64f9a01ffb3..f26630111c8bd05bf735bcd72f6de2facfdda25d 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
 struct bt_component;
 struct bt_private_component;
 
-extern struct bt_component *bt_component_from_private(
+extern struct bt_component *bt_component_borrow_from_private(
                struct bt_private_component *private_component);
 
 extern void *bt_private_component_get_user_data(
index 1a855e96a56fe9c1ca759b01b8416184064bd2cb..339cf80c44efa5e40f8cdeb0d83060312d8048c4 100644 (file)
@@ -34,7 +34,7 @@ struct bt_private_connection;
 struct bt_private_connection_private_notification_iterator;
 
 extern struct bt_notification_iterator *
-bt_private_connection_notification_iterator_from_private(
+bt_private_connection_notification_iterator_borrow_from_private(
                struct bt_private_connection_private_notification_iterator *private_notification_iterator);
 
 extern struct bt_private_component *
@@ -49,6 +49,9 @@ bt_private_connection_private_notification_iterator_set_user_data(
 extern void *bt_private_connection_private_notification_iterator_get_user_data(
                struct bt_private_connection_private_notification_iterator *private_notification_iterator);
 
+extern struct bt_graph *bt_private_connection_private_notification_iterator_borrow_graph(
+               struct bt_private_connection_private_notification_iterator *private_notification_iterator);
+
 #ifdef __cplusplus
 }
 #endif
index e62c1e36da917692bf711c5588fb14c048b051e6..c3692361264b6d33098f905a5a232acc3247ed8c 100644 (file)
@@ -36,7 +36,7 @@ struct bt_private_port;
 struct bt_private_connection;
 struct bt_notification_iterator;
 
-extern struct bt_connection *bt_connection_from_private(
+extern struct bt_connection *bt_connection_borrow_from_private(
                struct bt_private_connection *private_connection);
 
 extern enum bt_connection_status
index e109649f6d31f5c0a836364d57a5db3b6c7df93e..264de482f487887005a63dee9ed259ac7a9aba6a 100644 (file)
@@ -32,7 +32,8 @@ struct bt_private_port;
 struct bt_private_component;
 struct bt_private_connection;
 
-struct bt_port *bt_port_from_private(struct bt_private_port *private_port);
+struct bt_port *bt_port_borrow_from_private(
+               struct bt_private_port *private_port);
 extern struct bt_private_connection *bt_private_port_get_private_connection(
                struct bt_private_port *private_port);
 extern struct bt_private_component *bt_private_port_get_private_component(
index c414f79d96c808be2ba5433adfd043d39009fc72..45f519adf24ddc41e053c3dc4cf75314e80312a4 100644 (file)
@@ -131,7 +131,7 @@ void bt_stream_class_destroy(struct bt_object *obj)
         *
         * 4. Destroying an event makes it recycle its event header
         *    field to its stream class's event header field pool. But
-        *    said pool is already destroyed.
+        *    said pool is already finalized.
         */
        bt_stream_class_common_finalize(BT_TO_COMMON(stream_class));
        bt_object_pool_finalize(&stream_class->event_header_field_pool);
index 1c83b4b37bfd6ddf380fef35e389baee57e04bbb..185b8d10843e4f0d9aad45792ce2c9fb81d7b3b2 100644 (file)
@@ -144,10 +144,10 @@ void bt_component_destroy(struct bt_object *obj)
        g_free(component);
 }
 
-struct bt_component *bt_component_from_private(
+struct bt_component *bt_component_borrow_from_private(
                struct bt_private_component *private_component)
 {
-       return bt_get(bt_component_borrow_from_private(private_component));
+       return (void *) private_component;
 }
 
 enum bt_component_class_type bt_component_get_class_type(
@@ -371,10 +371,9 @@ void bt_component_set_graph(struct bt_component *component,
        bt_object_set_parent(component, graph ? &graph->base : NULL);
 }
 
-struct bt_graph *bt_component_get_graph(
-               struct bt_component *component)
+struct bt_graph *bt_component_borrow_graph(struct bt_component *component)
 {
-       return (struct bt_graph *) bt_object_get_parent(&component->base);
+       return (struct bt_graph *) bt_object_borrow_parent(&component->base);
 }
 
 static
index 73b5383dee347e0fe7a8ae1aa436032d9ce6e1e0..91d130edcf6c9147bcfac3f36ae69bde57bcc8b9 100644 (file)
@@ -117,10 +117,10 @@ void bt_connection_parent_is_owner(struct bt_object *obj)
        bt_connection_try_remove_from_graph(connection);
 }
 
-struct bt_connection *bt_connection_from_private(
+struct bt_connection *bt_connection_borrow_from_private(
                struct bt_private_connection *private_connection)
 {
-       return bt_get(bt_connection_borrow_from_private(private_connection));
+       return (void *) private_connection;
 }
 
 BT_HIDDEN
index 8914e1ef876477dd2135a1ea285a5e13b564bd48..a82270e795f34f6648c63a333c68ca224e8de4f2 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/values.h>
+#include <babeltrace/graph/private-component.h>
 #include <babeltrace/graph/component-filter-internal.h>
 #include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/component-class-internal.h>
index c7c27058c771b46e48d320735349f125ffb8d8af..d8181f0babb74f95c82b51ad991c20a4c2d67a35 100644 (file)
@@ -35,6 +35,9 @@
 #include <babeltrace/graph/component-source.h>
 #include <babeltrace/graph/component-filter.h>
 #include <babeltrace/graph/port.h>
+#include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/graph/notification-event-internal.h>
+#include <babeltrace/graph/notification-packet-internal.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/types.h>
 #include <babeltrace/values.h>
@@ -129,14 +132,20 @@ void bt_graph_destroy(struct bt_object *obj)
        call_remove_listeners(graph->listeners.ports_connected);
        call_remove_listeners(graph->listeners.ports_disconnected);
 
+       if (graph->notifications) {
+               g_ptr_array_free(graph->notifications, TRUE);
+       }
+
        if (graph->connections) {
                BT_LOGD_STR("Destroying connections.");
                g_ptr_array_free(graph->connections, TRUE);
        }
+
        if (graph->components) {
                BT_LOGD_STR("Destroying components.");
                g_ptr_array_free(graph->components, TRUE);
        }
+
        if (graph->sinks_to_consume) {
                g_queue_free(graph->sinks_to_consume);
        }
@@ -157,9 +166,39 @@ void bt_graph_destroy(struct bt_object *obj)
                g_array_free(graph->listeners.ports_disconnected, TRUE);
        }
 
+       bt_object_pool_finalize(&graph->event_notif_pool);
+       bt_object_pool_finalize(&graph->packet_begin_notif_pool);
+       bt_object_pool_finalize(&graph->packet_end_notif_pool);
        g_free(graph);
 }
 
+static
+void destroy_notification_event(struct bt_notification *notif,
+               struct bt_graph *graph)
+{
+       bt_notification_event_destroy(notif);
+}
+
+static
+void destroy_notification_packet_begin(struct bt_notification *notif,
+               struct bt_graph *graph)
+{
+       bt_notification_packet_begin_destroy(notif);
+}
+
+static
+void destroy_notification_packet_end(struct bt_notification *notif,
+               struct bt_graph *graph)
+{
+       bt_notification_packet_end_destroy(notif);
+}
+
+static
+void notify_notification_graph_is_destroyed(struct bt_notification *notif)
+{
+       bt_notification_unlink_graph(notif);
+}
+
 struct bt_graph *bt_graph_create(void)
 {
        struct bt_graph *graph;
@@ -215,6 +254,38 @@ struct bt_graph *bt_graph_create(void)
                goto error;
        }
 
+       ret = bt_object_pool_initialize(&graph->event_notif_pool,
+               (bt_object_pool_new_object_func) bt_notification_event_new,
+               (bt_object_pool_destroy_object_func) destroy_notification_event,
+               graph);
+       if (ret) {
+               BT_LOGE("Failed to initialize event notification pool: ret=%d",
+                       ret);
+               goto error;
+       }
+
+       ret = bt_object_pool_initialize(&graph->packet_begin_notif_pool,
+               (bt_object_pool_new_object_func) bt_notification_packet_begin_new,
+               (bt_object_pool_destroy_object_func) destroy_notification_packet_begin,
+               graph);
+       if (ret) {
+               BT_LOGE("Failed to initialize packet beginning notification pool: ret=%d",
+                       ret);
+               goto error;
+       }
+
+       ret = bt_object_pool_initialize(&graph->packet_end_notif_pool,
+               (bt_object_pool_new_object_func) bt_notification_packet_end_new,
+               (bt_object_pool_destroy_object_func) destroy_notification_packet_end,
+               graph);
+       if (ret) {
+               BT_LOGE("Failed to initialize packet end notification pool: ret=%d",
+                       ret);
+               goto error;
+       }
+
+       graph->notifications = g_ptr_array_new_with_free_func(
+               (GDestroyNotify) notify_notification_graph_is_destroyed);
        BT_LOGD("Created graph object: addr=%p", graph);
 
 end:
@@ -1187,3 +1258,21 @@ end:
        graph->can_consume = init_can_consume;
        return ret;
 }
+
+BT_HIDDEN
+void bt_graph_add_notification(struct bt_graph *graph,
+               struct bt_notification *notif)
+{
+       BT_ASSERT(graph);
+       BT_ASSERT(notif);
+
+       /*
+        * It's okay not to take a reference because, when a
+        * notification's reference count drops to 0, either:
+        *
+        * * It is recycled back to one of this graph's pool.
+        * * It is destroyed because it doesn't have any link to any
+        *   graph, which means the original graph is already destroyed.
+        */
+       g_ptr_array_add(graph->notifications, notif);
+}
index 61b5298bdcdc9c4bacac18760769de52f7c4b022..799888bc4f772b1e1bd01267f2ebe7da9b9183b9 100644 (file)
@@ -347,6 +347,7 @@ enum bt_connection_status bt_private_connection_notification_iterator_create(
        iterator->upstream_component = upstream_comp;
        iterator->upstream_port = upstream_port;
        iterator->connection = connection;
+       iterator->graph = bt_component_borrow_graph(upstream_comp);
        iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED;
        BT_LOGD("Created notification iterator: "
                "upstream-comp-addr=%p, upstream-comp-name=\"%s\", "
@@ -368,7 +369,7 @@ end:
 void *bt_private_connection_private_notification_iterator_get_user_data(
                struct bt_private_connection_private_notification_iterator *private_iterator)
 {
-       struct bt_notification_iterator_private_connection *iterator =
+       struct bt_notification_iterator_private_connection *iterator = (void *)
                bt_private_connection_notification_iterator_borrow_from_private(private_iterator);
 
        BT_ASSERT_PRE_NON_NULL(private_iterator, "Notification iterator");
@@ -380,7 +381,7 @@ bt_private_connection_private_notification_iterator_set_user_data(
                struct bt_private_connection_private_notification_iterator *private_iterator,
                void *data)
 {
-       struct bt_notification_iterator_private_connection *iterator =
+       struct bt_notification_iterator_private_connection *iterator = (void *)
                bt_private_connection_notification_iterator_borrow_from_private(private_iterator);
 
        BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator");
@@ -390,6 +391,17 @@ bt_private_connection_private_notification_iterator_set_user_data(
        return BT_NOTIFICATION_ITERATOR_STATUS_OK;
 }
 
+struct bt_graph *bt_private_connection_private_notification_iterator_borrow_graph(
+               struct bt_private_connection_private_notification_iterator *private_iterator)
+{
+       struct bt_notification_iterator_private_connection *iterator = (void *)
+               bt_private_connection_notification_iterator_borrow_from_private(
+                       private_iterator);
+
+       BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator");
+       return iterator->graph;
+}
+
 struct bt_notification *bt_notification_iterator_borrow_notification(
                struct bt_notification_iterator *iterator)
 {
@@ -1004,10 +1016,8 @@ end:
 }
 
 struct bt_notification_iterator *
-bt_private_connection_notification_iterator_from_private(
+bt_private_connection_notification_iterator_borrow_from_private(
                struct bt_private_connection_private_notification_iterator *private_notification_iterator)
 {
-       return bt_get(
-               bt_private_connection_notification_iterator_borrow_from_private(
-                       private_notification_iterator));
+       return (void *) private_notification_iterator;
 }
index 61bd98af1daddbc5e405cd821bfe6da8ef9182e5..2c837b109b9b52d27e0b29a72c9cbd9a5af202b2 100644 (file)
@@ -5,7 +5,6 @@ libgraph_notification_la_SOURCES = \
        packet.c \
        event.c \
        stream.c \
-       heap.c \
        inactivity.c \
        discarded-events.c \
        discarded-packets.c \
index 08fa0cbfe4e9b1011462f7766e951e03b3e91247..0dfd757966dc070740de2a48a0e501970077e331 100644 (file)
@@ -53,6 +53,7 @@ void bt_notification_discarded_elements_destroy(struct bt_object *obj)
 
 BT_HIDDEN
 struct bt_notification *bt_notification_discarded_elements_create(
+               struct bt_graph *graph,
                enum bt_notification_type type,
                struct bt_stream *stream,
                struct bt_clock_value *begin_clock_value,
@@ -77,7 +78,7 @@ struct bt_notification *bt_notification_discarded_elements_create(
        }
 
        bt_notification_init(&notification->parent, type,
-               bt_notification_discarded_elements_destroy);
+               bt_notification_discarded_elements_destroy, NULL);
        ret_notif = &notification->parent;
        notification->stream = bt_get(stream);
        notification->begin_clock_value = bt_get(begin_clock_value);
index 486a8b1018eb248780b3de2979ba75cc76f05ea2..3ed1c4cd0f6b6d351619bbdcd2497755c72d4c8b 100644 (file)
@@ -33,6 +33,7 @@
 #include <babeltrace/ctf-ir/event-class-internal.h>
 #include <babeltrace/ctf-ir/stream-class-internal.h>
 #include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/graph/clock-class-priority-map-internal.h>
 #include <babeltrace/graph/notification-event-internal.h>
 #include <stdbool.h>
 #include <inttypes.h>
 
-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(&notification->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(&notification->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 &notification->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(
diff --git a/lib/graph/notification/heap.c b/lib/graph/notification/heap.c
deleted file mode 100644 (file)
index f2d87a8..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Babeltrace - CTF notification priority heap
- *
- * Static-sized priority heap containing pointers. Based on CLRS,
- * chapter 6.
- *
- * Copyright (c) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * 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.
- */
-
-#include <stddef.h>
-#include <babeltrace/compiler-internal.h>
-#include <babeltrace/graph/notification-heap-internal.h>
-#include <babeltrace/assert-internal.h>
-
-#ifdef DEBUG_HEAP
-static
-void check_heap(struct bt_notification_heap *heap)
-{
-       size_t i;
-
-       if (!heap->count) {
-               return;
-       }
-
-       for (i = 1; i < heap->count; i++) {
-               BT_ASSERT(!heap->compare(g_ptr_array_index(heap->ptrs, i),
-                               g_ptr_array_index(heap->ptrs, 0),
-                               heap->compare_data));
-       }
-}
-#else
-void check_heap(struct bt_notification_heap *heap)
-{
-}
-#endif
-
-static
-size_t parent(size_t i)
-{
-       return (i - 1) >> 1;
-}
-
-static
-size_t left(size_t i)
-{
-       return (i << 1) + 1;
-}
-
-static
-size_t right(size_t i)
-{
-       return (i << 1) + 2;
-}
-
-/*
- * Copy of heap->ptrs pointer is invalid after heap_grow.
- */
-static
-int heap_grow(struct bt_notification_heap *heap, size_t new_len)
-{
-       size_t alloc_len;
-
-       if (likely(heap->ptrs->len >= new_len)) {
-               goto end;
-       }
-
-        alloc_len = max_t(size_t, new_len, heap->ptrs->len << 1);
-       g_ptr_array_set_size(heap->ptrs, alloc_len);
-end:
-       return 0;
-}
-
-static
-int heap_set_count(struct bt_notification_heap *heap, size_t new_count)
-{
-       int ret = 0;
-
-       ret = heap_grow(heap, new_count);
-       if (unlikely(ret)) {
-               goto end;
-       }
-       heap->count = new_count;
-end:
-       return ret;
-}
-
-static
-void heapify(struct bt_notification_heap *heap, size_t i)
-{
-       struct bt_notification **ptrs =
-                       (struct bt_notification **) heap->ptrs->pdata;
-
-       for (;;) {
-               void *tmp;
-               size_t l, r, largest;
-
-               l = left(i);
-               r = right(i);
-               if (l < heap->count && heap->compare(ptrs[l], ptrs[i],
-                               heap->compare_data)) {
-                       largest = l;
-               } else {
-                       largest = i;
-               }
-               if (r < heap->count && heap->compare(ptrs[r], ptrs[largest],
-                               heap->compare_data)) {
-                       largest = r;
-               }
-               if (unlikely(largest == i)) {
-                       break;
-               }
-               tmp = ptrs[i];
-               ptrs[i] = ptrs[largest];
-               ptrs[largest] = tmp;
-               i = largest;
-       }
-       check_heap(heap);
-}
-
-static
-struct bt_notification *heap_replace_max(struct bt_notification_heap *heap,
-               struct bt_notification *notification)
-{
-       struct bt_notification *res = NULL;
-
-       if (unlikely(!heap->count)) {
-               (void) heap_set_count(heap, 1);
-               g_ptr_array_index(heap->ptrs, 0) = notification;
-               check_heap(heap);
-               goto end;
-       }
-
-       /* Replace the current max and heapify. */
-       res = g_ptr_array_index(heap->ptrs, 0);
-       g_ptr_array_index(heap->ptrs, 0) = notification;
-       heapify(heap, 0);
-end:
-       return res;
-}
-
-static
-void bt_notification_heap_destroy(struct bt_object *obj)
-{
-       struct bt_notification_heap *heap = container_of(obj,
-                       struct bt_notification_heap, base);
-
-       if (heap->ptrs) {
-               size_t i;
-
-               for (i = 0; i < heap->count; i++) {
-                       bt_put(g_ptr_array_index(heap->ptrs, i));
-               }
-               g_ptr_array_free(heap->ptrs, TRUE);
-       }
-       g_free(heap);
-}
-
-struct bt_notification_heap *bt_notification_heap_create(
-               bt_notification_time_compare_func comparator, void *user_data)
-{
-       struct bt_notification_heap *heap = NULL;
-
-       if (!comparator) {
-               goto end;
-       }
-
-       heap = g_new0(struct bt_notification_heap, 1);
-       if (!heap) {
-               goto end;
-       }
-
-       bt_object_init(&heap->base, bt_notification_heap_destroy);
-       heap->ptrs = g_ptr_array_new();
-       if (!heap->ptrs) {
-               BT_PUT(heap);
-               goto end;
-       }
-
-       heap->compare = comparator;
-       heap->compare_data = user_data;
-end:
-       return heap;
-}
-
-struct bt_notification *bt_notification_heap_peek(
-               struct bt_notification_heap *heap)
-{
-       check_heap(heap);
-       return bt_get(likely(heap->count) ?
-                       g_ptr_array_index(heap->ptrs, 0) : NULL);
-}
-
-int bt_notification_heap_insert(struct bt_notification_heap *heap,
-               struct bt_notification *notification)
-{
-       int ret;
-       size_t pos;
-        struct bt_notification **ptrs;
-
-       ret = heap_set_count(heap, heap->count + 1);
-       if (unlikely(ret)) {
-               goto end;
-       }
-
-       ptrs = (struct bt_notification **) heap->ptrs->pdata;
-       pos = heap->count - 1;
-       while (pos > 0 && heap->compare(notification, ptrs[parent(pos)],
-                       heap->compare_data)) {
-               /* Move parent down until we find the right spot. */
-               ptrs[pos] = ptrs[parent(pos)];
-               pos = parent(pos);
-       }
-       ptrs[pos] = bt_get(notification);
-       check_heap(heap);
-end:
-       return ret;
-}
-
-struct bt_notification *bt_notification_heap_pop(
-               struct bt_notification_heap *heap)
-{
-        struct bt_notification *ret = NULL;
-
-       switch (heap->count) {
-       case 0:
-               goto end;
-       case 1:
-               (void) heap_set_count(heap, 0);
-               ret = g_ptr_array_index(heap->ptrs, 0);
-               goto end;
-       }
-       /*
-        * Shrink, replace the current max by previous last entry and heapify.
-        */
-       heap_set_count(heap, heap->count - 1);
-       /* count changed. previous last entry is at heap->count. */
-       ret = heap_replace_max(heap, g_ptr_array_index(heap->ptrs,
-                       heap->count));
-end:
-       /*
-        * Not taking a supplementary reference since we are relinquishing our
-        * own to the caller.
-        */
-       return ret;
-}
index 2575c14432f829b7d290932d9be2dca4511821a1..b6708d3b6ad5f4c74bbe11196449d05d636678cd 100644 (file)
@@ -52,6 +52,7 @@ void bt_notification_inactivity_destroy(struct bt_object *obj)
 }
 
 struct bt_notification *bt_notification_inactivity_create(
+               struct bt_graph *graph,
                struct bt_clock_class_priority_map *cc_prio_map)
 {
        struct bt_notification_inactivity *notification;
@@ -79,7 +80,7 @@ struct bt_notification *bt_notification_inactivity_create(
        }
        bt_notification_init(&notification->parent,
                BT_NOTIFICATION_TYPE_INACTIVITY,
-               bt_notification_inactivity_destroy);
+               bt_notification_inactivity_destroy, NULL);
        ret_notif = &notification->parent;
        notification->clock_values = g_hash_table_new_full(g_direct_hash,
                g_direct_equal, NULL, (GDestroyNotify) bt_clock_value_recycle);
index 57da6c333c3ae95c80d24babd2eec2bcff210ccf..0bcfb7dfbdacf225ba6f6898b1d105f5aba6f8e3 100644 (file)
 #include <babeltrace/lib-logging-internal.h>
 
 #include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/assert-internal.h>
 #include <babeltrace/assert-pre-internal.h>
 
 BT_ASSERT_PRE_FUNC
 static inline void _init_seq_num(struct bt_notification *notification)
 {
-       notification->seq_num = -1ULL;
+       notification->seq_num = UINT64_C(-1);
 }
 
 #ifdef BT_DEV_MODE
@@ -46,12 +47,18 @@ static inline void _init_seq_num(struct bt_notification *notification)
 BT_HIDDEN
 void bt_notification_init(struct bt_notification *notification,
                enum bt_notification_type type,
-               bt_object_release_func release)
+               bt_object_release_func release,
+               struct bt_graph *graph)
 {
        BT_ASSERT(type >= 0 && type < BT_NOTIFICATION_TYPE_NR);
        notification->type = type;
        init_seq_num(notification);
        bt_object_init(&notification->base, release);
+       notification->graph = graph;
+
+       if (graph) {
+               bt_graph_add_notification(graph, notification);
+       }
 }
 
 enum bt_notification_type bt_notification_get_type(
@@ -60,3 +67,10 @@ enum bt_notification_type bt_notification_get_type(
        BT_ASSERT_PRE_NON_NULL(notification, "Notification");
        return notification->type;
 }
+
+BT_HIDDEN
+void bt_notification_unlink_graph(struct bt_notification *notif)
+{
+       BT_ASSERT(notif);
+       notif->graph = NULL;
+}
index fb590c3c512c9611fc8c68c722ab77456af44f9f..17b00d463ee42a6c5341f25a98b3ffea0800cc61 100644 (file)
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/stream.h>
 #include <babeltrace/ctf-ir/stream-internal.h>
+#include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/graph/notification-packet-internal.h>
 #include <babeltrace/assert-internal.h>
 #include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 
-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(&notification->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_PUT(notification);
+
+end:
+       return (void *) notification;
 }
 
 struct bt_notification *bt_notification_packet_begin_create(
-               struct bt_packet *packet)
+               struct bt_graph *graph, struct bt_packet *packet)
 {
        struct bt_notification_packet_begin *notification;
        struct bt_stream *stream;
@@ -84,15 +83,13 @@ struct bt_notification *bt_notification_packet_begin_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class));
-       notification = g_new0(struct bt_notification_packet_begin, 1);
+       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.");
+               /* bt_notification_create_from_pool() logs errors */
                goto error;
        }
 
-       bt_notification_init(&notification->parent,
-                       BT_NOTIFICATION_TYPE_PACKET_BEGIN,
-                       bt_notification_packet_begin_destroy);
        notification->packet = bt_get(packet);
        BT_LOGD("Created packet beginning notification object: "
                "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
@@ -102,9 +99,45 @@ struct bt_notification *bt_notification_packet_begin_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class), notification);
-       return &notification->parent;
+       goto end;
+
 error:
-       return NULL;
+       BT_PUT(notification);
+
+end:
+       return (void *) notification;
+}
+
+BT_HIDDEN
+void bt_notification_packet_begin_destroy(struct bt_notification *notif)
+{
+       struct bt_notification_packet_begin *packet_begin_notif = (void *) notif;
+
+       BT_LOGD("Destroying packet beginning notification: addr=%p", notif);
+       BT_LOGD_STR("Putting packet.");
+       BT_PUT(packet_begin_notif->packet);
+       g_free(notif);
+}
+
+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 (!notif->graph) {
+               bt_notification_packet_begin_destroy(notif);
+               return;
+       }
+
+       BT_LOGD("Recycling packet beginning notification: addr=%p", notif);
+       bt_notification_reset(notif);
+       BT_PUT(packet_begin_notif->packet);
+       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(
@@ -120,8 +153,32 @@ struct bt_packet *bt_notification_packet_begin_borrow_packet(
        return packet_begin->packet;
 }
 
+BT_HIDDEN
+struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph)
+{
+       struct bt_notification_packet_end *notification;
+
+       notification = g_new0(struct bt_notification_packet_end, 1);
+       if (!notification) {
+               BT_LOGE_STR("Failed to allocate one packet end notification.");
+               goto error;
+       }
+
+       bt_notification_init(&notification->parent,
+                       BT_NOTIFICATION_TYPE_PACKET_END,
+                       (bt_object_release_func) bt_notification_packet_end_recycle,
+                       graph);
+       goto end;
+
+error:
+       BT_PUT(notification);
+
+end:
+       return (void *) notification;
+}
+
 struct bt_notification *bt_notification_packet_end_create(
-               struct bt_packet *packet)
+               struct bt_graph *graph, struct bt_packet *packet)
 {
        struct bt_notification_packet_end *notification;
        struct bt_stream *stream;
@@ -140,15 +197,13 @@ struct bt_notification *bt_notification_packet_end_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class));
-       notification = g_new0(struct bt_notification_packet_end, 1);
+       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.");
+               /* bt_notification_create_from_pool() logs errors */
                goto error;
        }
 
-       bt_notification_init(&notification->parent,
-                       BT_NOTIFICATION_TYPE_PACKET_END,
-                       bt_notification_packet_end_destroy);
        notification->packet = bt_get(packet);
        BT_LOGD("Created packet end notification object: "
                "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
@@ -158,9 +213,45 @@ struct bt_notification *bt_notification_packet_end_create(
                stream_class,
                bt_stream_class_get_name(stream_class),
                bt_stream_class_get_id(stream_class), notification);
-       return &notification->parent;
+       goto end;
+
 error:
-       return NULL;
+       BT_PUT(notification);
+
+end:
+       return (void *) notification;
+}
+
+BT_HIDDEN
+void bt_notification_packet_end_destroy(struct bt_notification *notif)
+{
+       struct bt_notification_packet_end *packet_end_notif = (void *) notif;
+
+       BT_LOGD("Destroying packet end notification: addr=%p", notif);
+       BT_LOGD_STR("Putting packet.");
+       BT_PUT(packet_end_notif->packet);
+       g_free(notif);
+}
+
+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_PUT(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(
index 8f35e3c631d849488c0b487290314344ea1cceb0..a1ce7a5aa995f1ebf98ead1048b0efe2e4b97c18 100644 (file)
@@ -49,7 +49,7 @@ void bt_notification_stream_end_destroy(struct bt_object *obj)
 }
 
 struct bt_notification *bt_notification_stream_end_create(
-               struct bt_stream *stream)
+               struct bt_graph *graph, struct bt_stream *stream)
 {
        struct bt_notification_stream_end *notification;
        struct bt_stream_class *stream_class;
@@ -73,7 +73,7 @@ struct bt_notification *bt_notification_stream_end_create(
 
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_STREAM_END,
-                       bt_notification_stream_end_destroy);
+                       bt_notification_stream_end_destroy, NULL);
        notification->stream = bt_get(stream);
        BT_LOGD("Created stream end notification object: "
                "stream-addr=%p, stream-name=\"%s\", "
@@ -115,7 +115,7 @@ void bt_notification_stream_begin_destroy(struct bt_object *obj)
 }
 
 struct bt_notification *bt_notification_stream_begin_create(
-               struct bt_stream *stream)
+               struct bt_graph *graph, struct bt_stream *stream)
 {
        struct bt_notification_stream_begin *notification;
        struct bt_stream_class *stream_class;
@@ -139,7 +139,7 @@ struct bt_notification *bt_notification_stream_begin_create(
 
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_STREAM_BEGIN,
-                       bt_notification_stream_begin_destroy);
+                       bt_notification_stream_begin_destroy, NULL);
        notification->stream = bt_get(stream);
        BT_LOGD("Created stream beginning notification object: "
                "stream-addr=%p, stream-name=\"%s\", "
index 25b427d2d0048a9ff7dc7b08ece32dfaf369c325..950a0a26528133327ffc8675beb3cd40b87f1f9a 100644 (file)
@@ -52,10 +52,10 @@ void bt_port_destroy(struct bt_object *obj)
        g_free(port);
 }
 
-struct bt_port *bt_port_from_private(
+struct bt_port *bt_port_borrow_from_private(
                struct bt_private_port *private_port)
 {
-       return bt_get(bt_port_borrow_from_private(private_port));
+       return (void *) private_port;
 }
 
 BT_HIDDEN
index 5c8bec7a910fb00e13fbd858f252ea5a7cf26fa7..bee8403cc5a65772698072c5dc4969b3407c1ef4 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/values.h>
+#include <babeltrace/graph/private-component.h>
 #include <babeltrace/graph/component-sink-internal.h>
 #include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/notification.h>
index afdb3765107cd148600e656ff7f25f5ff5447e9a..52ac8c81da502dd2725f365ed0e350d623bb0073 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <babeltrace/ref.h>
 #include <babeltrace/compiler-internal.h>
+#include <babeltrace/graph/private-component.h>
 #include <babeltrace/graph/component-source-internal.h>
 #include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/port-internal.h>
index 214c2e3ae2c36f91ce357fcf4adf1b4d054ed861..d1ac59e6e349cf18e4554eab67559b9f669b7f4d 100644 (file)
@@ -66,7 +66,6 @@
 #include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/graph/notification-discarded-elements-internal.h>
 #include <babeltrace/graph/notification-event-internal.h>
-#include <babeltrace/graph/notification-heap-internal.h>
 #include <babeltrace/graph/notification-inactivity-internal.h>
 #include <babeltrace/graph/notification-internal.h>
 #include <babeltrace/graph/notification-iterator-internal.h>
@@ -586,6 +585,9 @@ static inline void format_stream_class(char **buf_ch, bool extended,
        SET_TMP_PREFIX("ehf-pool-");
        format_object_pool(buf_ch, extended, prefix,
                &stream_class->event_header_field_pool);
+       SET_TMP_PREFIX("pcf-pool-");
+       format_object_pool(buf_ch, extended, prefix,
+               &stream_class->packet_context_field_pool);
 }
 
 static inline void format_writer_stream_class(char **buf_ch, bool extended,
@@ -1038,7 +1040,8 @@ static inline void format_notification(char **buf_ch, bool extended,
                return;
        }
 
-       BUF_APPEND(", %sis-frozen=%d", PRFIELD(notif->frozen));
+       BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
+               PRFIELD(notif->frozen), PRFIELD(notif->graph));
 
        switch (notif->type) {
        case BT_NOTIFICATION_TYPE_EVENT:
@@ -1240,6 +1243,8 @@ static inline void format_connection(char **buf_ch, bool extended,
 static inline void format_graph(char **buf_ch, bool extended,
                const char *prefix, struct bt_graph *graph)
 {
+       char tmp_prefix[64];
+
        BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph->canceled));
 
        if (!extended) {
@@ -1255,6 +1260,16 @@ static inline void format_graph(char **buf_ch, bool extended,
                BUF_APPEND(", %sconn-count=%u",
                        PRFIELD(graph->connections->len));
        }
+
+       SET_TMP_PREFIX("en-pool-");
+       format_object_pool(buf_ch, extended, prefix,
+               &graph->event_notif_pool);
+       SET_TMP_PREFIX("pbn-pool-");
+       format_object_pool(buf_ch, extended, prefix,
+               &graph->packet_begin_notif_pool);
+       SET_TMP_PREFIX("pen-pool-");
+       format_object_pool(buf_ch, extended, prefix,
+               &graph->packet_end_notif_pool);
 }
 
 static inline void format_notification_iterator(char **buf_ch,
index 7128e184ba3821272e1d689415b9c0c795a06843..4f295a4d31acc6665c6ddd060eb0733ed11f3d2e 100644 (file)
@@ -132,6 +132,9 @@ struct bt_notif_iter {
        /* Visit stack */
        struct stack *stack;
 
+       /* Current graph to create notifications (weak) */
+       struct bt_graph *graph;
+
        /*
         * Current dynamic scope field pointer.
         *
@@ -1582,8 +1585,10 @@ enum bt_notif_iter_status set_current_event_notification(
                notit, notit->meta.event_class,
                bt_event_class_get_name(notit->meta.event_class),
                notit->packet);
-       notif = bt_notification_event_create(notit->meta.event_class,
-               notit->packet, notit->meta.cc_prio_map);
+       BT_ASSERT(notit->graph);
+       notif = bt_notification_event_create(notit->graph,
+               notit->meta.event_class, notit->packet,
+               notit->meta.cc_prio_map);
        if (!notif) {
                BT_LOGE("Cannot create event notification: "
                        "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", "
@@ -2759,7 +2764,8 @@ void notify_new_stream(struct bt_notif_iter *notit,
        }
 
        BT_ASSERT(notit->stream);
-       ret = bt_notification_stream_begin_create(notit->stream);
+       BT_ASSERT(notit->graph);
+       ret = bt_notification_stream_begin_create(notit->graph, notit->stream);
        if (!ret) {
                BT_LOGE("Cannot create stream beginning notification: "
                        "notit-addr=%p, stream-addr=%p",
@@ -2783,7 +2789,8 @@ void notify_end_of_stream(struct bt_notif_iter *notit,
                return;
        }
 
-       ret = bt_notification_stream_end_create(notit->stream);
+       BT_ASSERT(notit->graph);
+       ret = bt_notification_stream_end_create(notit->graph, notit->stream);
        if (!ret) {
                BT_LOGE("Cannot create stream beginning notification: "
                        "notit-addr=%p, stream-addr=%p",
@@ -2844,7 +2851,9 @@ void notify_new_packet(struct bt_notif_iter *notit,
                        notit->dscopes.stream_packet_context);
        }
 
-       notif = bt_notification_packet_begin_create(notit->packet);
+       BT_ASSERT(notit->graph);
+       notif = bt_notification_packet_begin_create(notit->graph,
+               notit->packet);
        if (!notif) {
                BT_LOGE("Cannot create packet beginning notification: "
                        "notit-addr=%p, packet-addr=%p",
@@ -2866,7 +2875,8 @@ void notify_end_of_packet(struct bt_notif_iter *notit,
                return;
        }
 
-       notif = bt_notification_packet_end_create(notit->packet);
+       BT_ASSERT(notit->graph);
+       notif = bt_notification_packet_end_create(notit->graph, notit->packet);
        if (!notif) {
                BT_LOGE("Cannot create packet end notification: "
                        "notit-addr=%p, packet-addr=%p",
@@ -3051,6 +3061,7 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notit)
 enum bt_notif_iter_status bt_notif_iter_get_next_notification(
                struct bt_notif_iter *notit,
                struct bt_clock_class_priority_map *cc_prio_map,
+               struct bt_graph *graph,
                struct bt_notification **notification)
 {
        int ret;
@@ -3059,15 +3070,17 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification(
        BT_ASSERT(notit);
        BT_ASSERT(notification);
 
+       if (notit->state == STATE_DONE) {
+               status = BT_NOTIF_ITER_STATUS_EOF;
+               goto end;
+       }
+
        if (cc_prio_map != notit->meta.cc_prio_map) {
                bt_put(notit->meta.cc_prio_map);
                notit->meta.cc_prio_map = bt_get(cc_prio_map);
        }
 
-       if (notit->state == STATE_DONE) {
-               status = BT_NOTIF_ITER_STATUS_EOF;
-               goto end;
-       }
+       notit->graph = graph;
 
        BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p",
                notit, cc_prio_map);
index baaa9cd67e7854103f8fddd50bcf92262607633d..ae9b511a922704c0d99c66a84560d23ed66b4ac0 100644 (file)
@@ -314,6 +314,7 @@ BT_HIDDEN
 enum bt_notif_iter_status bt_notif_iter_get_next_notification(
                struct bt_notif_iter *notit,
                struct bt_clock_class_priority_map *cc_prio_map,
+               struct bt_graph *graph,
                struct bt_notification **notification);
 
 /**
index 2b97ca3a2c556b8c1f4e611fa997ac8f1b9a2d53..76f5688a412a7670942477adb19b8a8122d51c86 100644 (file)
@@ -737,7 +737,7 @@ error:
 BT_HIDDEN
 struct ctf_fs_ds_file *ctf_fs_ds_file_create(
                struct ctf_fs_trace *ctf_fs_trace,
-               struct bt_notif_iter *notif_iter,
+               struct bt_graph *graph, struct bt_notif_iter *notif_iter,
                struct bt_stream *stream, const char *path)
 {
        int ret;
@@ -748,6 +748,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(
                goto error;
        }
 
+       ds_file->graph = graph;
        ds_file->file = ctf_fs_file_create();
        if (!ds_file->file) {
                goto error;
@@ -827,7 +828,8 @@ struct bt_notification_iterator_next_method_return ctf_fs_ds_file_next(
        };
 
        notif_iter_status = bt_notif_iter_get_next_notification(
-               ds_file->notif_iter, ds_file->cc_prio_map, &ret.notification);
+               ds_file->notif_iter, ds_file->cc_prio_map, ds_file->graph,
+               &ret.notification);
 
        switch (notif_iter_status) {
        case BT_NOTIF_ITER_STATUS_EOF:
index e1620b9f601c4fddba5cc1f7184397782f1dc45a..e7d8b04acb5ac8f0ad8ed09735b9ff32577a113d 100644 (file)
@@ -85,6 +85,9 @@ struct ctf_fs_ds_file_info {
 };
 
 struct ctf_fs_ds_file {
+       /* Weak */
+       struct bt_graph *graph;
+
        /* Owned by this */
        struct ctf_fs_file *file;
 
@@ -123,6 +126,7 @@ struct ctf_fs_ds_file {
 BT_HIDDEN
 struct ctf_fs_ds_file *ctf_fs_ds_file_create(
                struct ctf_fs_trace *ctf_fs_trace,
+               struct bt_graph *graph,
                struct bt_notif_iter *notif_iter,
                struct bt_stream *stream, const char *path);
 
index 07b4c049fc28bbd0ca155f6ab239a1921197f965..04421d3147a8f3b5f70ea5e9b555181dab9a1c8c 100644 (file)
@@ -59,6 +59,7 @@ int notif_iter_data_set_current_ds_file(struct ctf_fs_notif_iter_data *notif_ite
        ctf_fs_ds_file_destroy(notif_iter_data->ds_file);
        notif_iter_data->ds_file = ctf_fs_ds_file_create(
                notif_iter_data->ds_file_group->ctf_fs_trace,
+               notif_iter_data->graph,
                notif_iter_data->notif_iter,
                notif_iter_data->ds_file_group->stream,
                ds_file_info->path->str);
@@ -215,6 +216,8 @@ enum bt_notification_iterator_status ctf_fs_iterator_init(
                goto error;
        }
 
+       notif_iter_data->graph = bt_component_borrow_graph(
+               bt_component_borrow_from_private(port_data->ctf_fs->priv_comp));
        notif_iter_data->notif_iter = bt_notif_iter_create(
                port_data->ds_file_group->ctf_fs_trace->metadata->trace,
                bt_common_get_page_size() * 8,
@@ -366,6 +369,7 @@ int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
                goto error;
        }
 
+       port_data->ctf_fs = ctf_fs;
        port_data->ds_file_group = ds_file_group;
        ret = bt_private_component_source_add_output_private_port(
                ctf_fs->priv_comp, port_name->str, port_data, NULL);
@@ -642,7 +646,7 @@ end:
 
 static
 int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace,
-               const char *path)
+               struct bt_graph *graph, const char *path)
 {
        struct bt_field *packet_header_field = NULL;
        struct bt_field *packet_context_field = NULL;
@@ -664,7 +668,8 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace,
                goto error;
        }
 
-       ds_file = ctf_fs_ds_file_create(ctf_fs_trace, notif_iter, NULL, path);
+       ds_file = ctf_fs_ds_file_create(ctf_fs_trace, graph, notif_iter,
+               NULL, path);
        if (!ds_file) {
                goto error;
        }
@@ -784,7 +789,8 @@ end:
 }
 
 static
-int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
+int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace,
+               struct bt_graph *graph)
 {
        int ret = 0;
        const char *basename;
@@ -849,7 +855,7 @@ int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
                        continue;
                }
 
-               ret = add_ds_file_to_ds_file_group(ctf_fs_trace,
+               ret = add_ds_file_to_ds_file_group(ctf_fs_trace, graph,
                        file->path->str);
                if (ret) {
                        BT_LOGE("Cannot add stream file `%s` to stream file group",
@@ -956,7 +962,8 @@ end:
 
 BT_HIDDEN
 struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
-               struct ctf_fs_metadata_config *metadata_config)
+               struct ctf_fs_metadata_config *metadata_config,
+               struct bt_graph *graph)
 {
        struct ctf_fs_trace *ctf_fs_trace;
        int ret;
@@ -992,7 +999,7 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
                goto error;
        }
 
-       ret = create_ds_file_groups(ctf_fs_trace);
+       ret = create_ds_file_groups(ctf_fs_trace, graph);
        if (ret) {
                goto error;
        }
@@ -1238,9 +1245,13 @@ int create_ctf_fs_traces(struct ctf_fs_component *ctf_fs,
                        tn_node = g_list_next(tn_node)) {
                GString *trace_path = tp_node->data;
                GString *trace_name = tn_node->data;
+               struct bt_graph *graph = bt_component_borrow_graph(
+                       bt_component_borrow_from_private(ctf_fs->priv_comp));
 
+               BT_ASSERT(graph);
                ctf_fs_trace = ctf_fs_trace_create(trace_path->str,
-                               trace_name->str, &ctf_fs->metadata_config);
+                               trace_name->str, &ctf_fs->metadata_config,
+                               graph);
                if (!ctf_fs_trace) {
                        BT_LOGE("Cannot create trace for `%s`.",
                                trace_path->str);
index 1124a0f39a7184a302fc93aee2393799690f4111..b54e4722d323caa1a3746e9a8228ac1cd13fc1dd 100644 (file)
@@ -120,9 +120,15 @@ struct ctf_fs_ds_file_group {
 struct ctf_fs_port_data {
        /* Weak, belongs to ctf_fs_trace */
        struct ctf_fs_ds_file_group *ds_file_group;
+
+       /* Weak */
+       struct ctf_fs_component *ctf_fs;
 };
 
 struct ctf_fs_notif_iter_data {
+       /* Weak */
+       struct bt_graph *graph;
+
        /* Weak, belongs to ctf_fs_trace */
        struct ctf_fs_ds_file_group *ds_file_group;
 
@@ -154,7 +160,7 @@ struct bt_component_class_query_method_return ctf_fs_query(
 
 BT_HIDDEN
 struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
-               struct ctf_fs_metadata_config *config);
+               struct ctf_fs_metadata_config *config, struct bt_graph *graph);
 
 BT_HIDDEN
 void ctf_fs_trace_destroy(struct ctf_fs_trace *trace);
index a54cbb0d659c59e5241fc43f103202cd01729f06..96bf91ca0eaa11c7a6a67934d66527c1377ad0e9 100644 (file)
@@ -381,7 +381,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name,
                goto end;
        }
 
-       trace = ctf_fs_trace_create(trace_path, trace_name, NULL);
+       trace = ctf_fs_trace_create(trace_path, trace_name, NULL, NULL);
        if (!trace) {
                BT_LOGE("Failed to create fs trace at \'%s\'", trace_path);
                ret = -1;
index 7d208ed35b50eb23616a0b440388ab3082b6c546..9f0d9e1cbe8f6ca8b426e72ac5884bba445f9b9a 100644 (file)
@@ -66,6 +66,7 @@ struct dmesg_component {
                bt_bool no_timestamp;
        } params;
 
+       struct bt_graph *graph; /* Weak */
        struct bt_trace *trace;
        struct bt_stream_class *stream_class;
        struct bt_event_class *event_class;
@@ -546,6 +547,9 @@ enum bt_component_status dmesg_init(struct bt_private_component *priv_comp,
                goto error;
        }
 
+       dmesg_comp->graph = bt_component_borrow_graph(
+               bt_component_borrow_from_private(priv_comp));
+       BT_ASSERT(dmesg_comp->graph);
        dmesg_comp->params.path = g_string_new(NULL);
        if (!dmesg_comp->params.path) {
                BT_LOGE_STR("Failed to allocate a GString.");
@@ -672,8 +676,9 @@ skip_ts:
                goto error;
        }
 
-       notif = bt_notification_event_create(dmesg_comp->event_class,
-               dmesg_comp->packet, dmesg_comp->cc_prio_map);
+       notif = bt_notification_event_create(dmesg_comp->graph,
+               dmesg_comp->event_class, dmesg_comp->packet,
+               dmesg_comp->cc_prio_map);
        if (!notif) {
                BT_LOGE_STR("Cannot create event notification.");
                goto error;
@@ -957,13 +962,13 @@ handle_state:
        case STATE_EMIT_STREAM_BEGINNING:
                BT_ASSERT(dmesg_notif_iter->tmp_event_notif);
                next_ret.notification = bt_notification_stream_begin_create(
-                       dmesg_comp->stream);
+                       dmesg_comp->graph, dmesg_comp->stream);
                dmesg_notif_iter->state = STATE_EMIT_PACKET_BEGINNING;
                break;
        case STATE_EMIT_PACKET_BEGINNING:
                BT_ASSERT(dmesg_notif_iter->tmp_event_notif);
                next_ret.notification = bt_notification_packet_begin_create(
-                       dmesg_comp->packet);
+                       dmesg_comp->graph, dmesg_comp->packet);
                dmesg_notif_iter->state = STATE_EMIT_EVENT;
                break;
        case STATE_EMIT_EVENT:
@@ -973,12 +978,12 @@ handle_state:
                break;
        case STATE_EMIT_PACKET_END:
                next_ret.notification = bt_notification_packet_end_create(
-                       dmesg_comp->packet);
+                       dmesg_comp->graph, dmesg_comp->packet);
                dmesg_notif_iter->state = STATE_EMIT_STREAM_END;
                break;
        case STATE_EMIT_STREAM_END:
                next_ret.notification = bt_notification_stream_end_create(
-                       dmesg_comp->stream);
+                       dmesg_comp->graph, dmesg_comp->stream);
                dmesg_notif_iter->state = STATE_DONE;
                break;
        default:
index b349ce1f62befe46195b5608b60deda882ff633b..1f87b2162b3b73b6a9e43b515df094a4bea2504c 100644 (file)
@@ -406,7 +406,7 @@ static
 struct bt_notification_iterator *create_notif_iter_on_input_port(
                struct bt_private_port *priv_port, int *ret)
 {
-       struct bt_port *port = bt_port_from_private(priv_port);
+       struct bt_port *port = bt_port_borrow_from_private(priv_port);
        struct bt_notification_iterator *notif_iter = NULL;
        struct bt_private_connection *priv_conn = NULL;
        enum bt_connection_status conn_status;
@@ -439,7 +439,6 @@ struct bt_notification_iterator *create_notif_iter_on_input_port(
                port, bt_port_get_name(port), priv_conn, notif_iter);
 
 end:
-       bt_put(port);
        bt_put(priv_conn);
        return notif_iter;
 }
@@ -530,7 +529,7 @@ int muxer_notif_iter_handle_newly_connected_ports(
                }
 
                priv_port = node->data;
-               port = bt_port_from_private(priv_port);
+               port = bt_port_borrow_from_private(priv_port);
                BT_ASSERT(port);
 
                if (!bt_port_is_connected(port)) {
@@ -543,7 +542,6 @@ int muxer_notif_iter_handle_newly_connected_ports(
                        goto remove_node;
                }
 
-               BT_PUT(port);
                upstream_notif_iter = create_notif_iter_on_input_port(priv_port,
                        &ret);
                if (ret) {
@@ -567,7 +565,6 @@ int muxer_notif_iter_handle_newly_connected_ports(
 
 remove_node:
                bt_put(upstream_notif_iter);
-               bt_put(port);
                muxer_notif_iter->newly_connected_priv_ports =
                        g_list_delete_link(
                                muxer_notif_iter->newly_connected_priv_ports,
@@ -1159,7 +1156,7 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp,
         * iterator's list of newly connected ports. They will be
         * handled by muxer_notif_iter_handle_newly_connected_ports().
         */
-       comp = bt_component_from_private(muxer_comp->priv_comp);
+       comp = bt_component_borrow_from_private(muxer_comp->priv_comp);
        BT_ASSERT(comp);
        count = bt_component_filter_get_input_port_count(comp);
        if (count < 0) {
@@ -1176,7 +1173,7 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp,
                struct bt_port *port;
 
                BT_ASSERT(priv_port);
-               port = bt_port_from_private(priv_port);
+               port = bt_port_borrow_from_private(priv_port);
                BT_ASSERT(port);
 
                if (!bt_port_is_connected(port)) {
@@ -1184,11 +1181,9 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp,
                                "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
                                muxer_comp, port, bt_port_get_name(port));
                        bt_put(priv_port);
-                       bt_put(port);
                        continue;
                }
 
-               bt_put(port);
                bt_put(priv_port);
                muxer_notif_iter->newly_connected_priv_ports =
                        g_list_append(
@@ -1210,7 +1205,6 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp,
        }
 
 end:
-       bt_put(comp);
        return ret;
 }
 
@@ -1397,7 +1391,7 @@ void muxer_port_connected(
                struct bt_port *other_port)
 {
        struct bt_port *self_port =
-               bt_port_from_private(self_private_port);
+               bt_port_borrow_from_private(self_private_port);
        struct muxer_comp *muxer_comp =
                bt_private_component_get_user_data(priv_comp);
        size_t i;
@@ -1462,14 +1456,14 @@ void muxer_port_connected(
        }
 
 end:
-       bt_put(self_port);
+       return;
 }
 
 BT_HIDDEN
 void muxer_port_disconnected(struct bt_private_component *priv_comp,
                struct bt_private_port *priv_port)
 {
-       struct bt_port *port = bt_port_from_private(priv_port);
+       struct bt_port *port = bt_port_borrow_from_private(priv_port);
        struct muxer_comp *muxer_comp =
                bt_private_component_get_user_data(priv_comp);
 
@@ -1500,6 +1494,4 @@ void muxer_port_disconnected(struct bt_private_component *priv_comp,
                        priv_comp, muxer_comp, port, bt_port_get_name(port),
                        muxer_comp->available_input_ports);
        }
-
-       bt_put(port);
 }
index 88dce23a0db44cfec148cff068b50931e5e82887..05e9439e8eb9b6b3fec2f9dc07e0f4bc50cadbcb 100644 (file)
@@ -29,7 +29,6 @@ TESTS_LIB = \
        lib/test_ctf_ir_ref \
        lib/test_bt_ctf_field_type_validation \
        lib/test_ir_visit \
-       lib/test_bt_notification_heap \
        lib/test_graph_topo \
        lib/test_cc_prio_map \
        lib/test_bt_notification_iterator
index 6b7030ee4480aa0466629fdba85fec41cdfa4b44..1ee9fffb49b177c12088df3687af576f5351f76d 100644 (file)
@@ -25,8 +25,6 @@ test_bt_ctf_field_type_validation_LDADD = $(COMMON_TEST_LDADD)
 
 test_ir_visit_LDADD = $(COMMON_TEST_LDADD)
 
-test_bt_notification_heap_LDADD = $(COMMON_TEST_LDADD)
-
 test_graph_topo_LDADD = $(COMMON_TEST_LDADD)
 
 test_cc_prio_map_LDADD = $(COMMON_TEST_LDADD)
@@ -35,8 +33,7 @@ test_bt_notification_iterator_LDADD = $(COMMON_TEST_LDADD)
 
 noinst_PROGRAMS = test_bitfield test_ctf_writer test_bt_values \
        test_ctf_ir_ref test_bt_ctf_field_type_validation test_ir_visit \
-       test_bt_notification_heap test_graph_topo \
-       test_cc_prio_map test_bt_notification_iterator
+       test_graph_topo test_cc_prio_map test_bt_notification_iterator
 
 test_bitfield_SOURCES = test_bitfield.c
 test_ctf_writer_SOURCES = test_ctf_writer.c
@@ -44,7 +41,6 @@ test_bt_values_SOURCES = test_bt_values.c
 test_ctf_ir_ref_SOURCES = test_ctf_ir_ref.c
 test_bt_ctf_field_type_validation_SOURCES = test_bt_ctf_field_type_validation.c
 test_ir_visit_SOURCES = test_ir_visit.c
-test_bt_notification_heap_SOURCES = test_bt_notification_heap.c
 test_graph_topo_SOURCES = test_graph_topo.c
 test_cc_prio_map_SOURCES = test_cc_prio_map.c
 test_bt_notification_iterator_SOURCES = test_bt_notification_iterator.c
diff --git a/tests/lib/test_bt_notification_heap.c b/tests/lib/test_bt_notification_heap.c
deleted file mode 100644 (file)
index 531ddf6..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * test_bt_notification_heap.c
- *
- * bt_notification_heap tests
- *
- * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; under version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "tap/tap.h"
-#include <stdlib.h>
-#include <babeltrace/compiler-internal.h>
-#include <babeltrace/ref.h>
-#include <babeltrace/graph/notification-heap.h>
-#include <babeltrace/graph/notification.h>
-#include <babeltrace/graph/notification-internal.h>
-
-#define NR_TESTS 7
-
-struct dummy_notification {
-       struct bt_notification parent;
-       uint64_t value;
-};
-
-static
-void dummy_notification_destroy(struct bt_object *obj)
-{
-       g_free(obj);
-}
-
-/* Reproduced from internal notification.c code. */
-void bt_notification_init(struct bt_notification *notification,
-               enum bt_notification_type type,
-               bt_object_release_func release)
-{
-       assert(type > 0 && type < BT_NOTIFICATION_TYPE_NR);
-       notification->type = type;
-       bt_object_init(&notification->base, release);
-}
-
-static
-struct bt_notification *dummy_notification_create(uint64_t value)
-{
-       struct dummy_notification *notification;
-
-       notification = g_new0(struct dummy_notification, 1);
-       if (!notification) {
-               goto error;
-       }
-       bt_notification_init(&notification->parent,
-                       BT_NOTIFICATION_TYPE_NR - 1 /* dummy value */,
-                       dummy_notification_destroy);
-       notification->value = value;
-       return &notification->parent;
-error:
-       return NULL;
-}
-
-static
-bt_bool compare_notifications(struct bt_notification *a, struct bt_notification *b,
-               void *unused)
-{
-       uint64_t val_a = ((struct dummy_notification *) a)->value;
-       uint64_t val_b = ((struct dummy_notification *) b)->value;
-
-       if (val_a == val_b) {
-               return a < b;
-       } else {
-               return val_a < val_b;
-       }
-}
-
-int main(int argc, char **argv)
-{
-       int i;
-       uint64_t last_read_value = 0;
-       struct bt_notification_heap *heap = NULL;
-
-       /* Initialize tap harness before any tests */
-       plan_tests(NR_TESTS);
-       heap = bt_notification_heap_create(compare_notifications, NULL);
-       ok(heap, "Created a notification heap");
-
-       /* Insert 10 000 notifications with random values. */
-       for (i = 0; i < 10000; i++) {
-               int ret;
-               struct bt_notification *notification =
-                               dummy_notification_create(rand());
-
-               if (!notification) {
-                       diag("Dummy notification creation failed");
-                       goto end;
-               }
-
-               ret = bt_notification_heap_insert(heap, notification);
-               if (ret) {
-                       diag("Failed to insert notification %i in heap", i);
-                       goto end;
-               }
-               bt_put(notification);
-       }
-       pass("Inserted 10 000 random notifications in notification heap");
-
-       /* Pop 5000 notifications, making sure the values read are ascending */
-       for (i = 0; i < 5000; i++) {
-               struct bt_notification *pop_notification;
-               struct bt_notification *peek_notification;
-               struct dummy_notification *dummy;
-
-               peek_notification = bt_notification_heap_peek(heap);
-               if (!peek_notification) {
-                       fail("Failed to peek a notification");
-                       goto end;
-               }
-
-               pop_notification = bt_notification_heap_pop(heap);
-               if (!pop_notification) {
-                       fail("Failed to pop a notification");
-                       goto end;
-               }
-
-               if (peek_notification != pop_notification) {
-                       fail("bt_notification_heap_peek and bt_notification_heap_pop do not return the same notification");
-                       bt_put(peek_notification);
-                       bt_put(pop_notification);
-                       goto end;
-               }
-
-               dummy = container_of(pop_notification,
-                               struct dummy_notification, parent);
-               if (dummy->value < last_read_value) {
-                       fail("Notification heap did not provide notifications in ascending order");
-               }
-               last_read_value = dummy->value;
-               bt_put(peek_notification);
-               bt_put(pop_notification);
-       }
-
-       pass("bt_notification_heap_peek and bt_notification_heap_pop return the same notification");
-       pass("Notification heap provided 5 000 notifications in ascending order");
-
-       /* Insert 10 000 notifications with random values. */
-       for (i = 0; i < 10000; i++) {
-               int ret;
-               struct bt_notification *notification =
-                               dummy_notification_create(rand());
-
-               if (!notification) {
-                       diag("Dummy notification creation failed");
-                       goto end;
-               }
-
-               ret = bt_notification_heap_insert(heap, notification);
-               if (ret) {
-                       diag("Failed to insert notification %i in heap", i);
-                       goto end;
-               }
-               bt_put(notification);
-       }
-       pass("Inserted 10 000 random notifications in notification heap after popping");
-
-       last_read_value = 0;
-       /* Pop remaining 15 000 notifications, making sure the values read are ascending */
-       for (i = 0; i < 15000; i++) {
-               struct bt_notification *pop_notification;
-               struct dummy_notification *dummy;
-
-               pop_notification = bt_notification_heap_pop(heap);
-               if (!pop_notification) {
-                       fail("Failed to pop a notification");
-                       goto end;
-               }
-               dummy = container_of(pop_notification,
-                               struct dummy_notification, parent);
-               if (dummy->value < last_read_value) {
-                       fail("Notification heap did not provide notifications in ascending order");
-               }
-               last_read_value = dummy->value;
-               bt_put(pop_notification);
-       }
-       pass("Popped remaining 15 000 notifications from heap in ascending order");
-
-       ok(!bt_notification_heap_peek(heap), "No notifications left in heap");
-end:
-       bt_put(heap);
-       return exit_status();
-}
index 8f889fcda1dad29677dc0a66517b1e1df61d0752..be3f6dd85013aa61926bf5317454165113f0d99b 100644 (file)
@@ -87,6 +87,7 @@ struct test_event {
 static bool debug = false;
 static enum test current_test;
 static GArray *test_events;
+static struct bt_graph *graph;
 static struct bt_clock_class_priority_map *src_empty_cc_prio_map;
 static struct bt_stream_class *src_stream_class;
 static struct bt_event_class *src_event_class;
@@ -421,67 +422,76 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq(
                break;
        case SEQ_INACTIVITY:
                next_return.notification =
-                       bt_notification_inactivity_create(src_empty_cc_prio_map);
+                       bt_notification_inactivity_create(graph,
+                               src_empty_cc_prio_map);
                assert(next_return.notification);
                break;
        case SEQ_STREAM1_BEGIN:
                next_return.notification =
-                       bt_notification_stream_begin_create(src_stream1);
+                       bt_notification_stream_begin_create(graph, src_stream1);
                assert(next_return.notification);
                break;
        case SEQ_STREAM2_BEGIN:
                next_return.notification =
-                       bt_notification_stream_begin_create(src_stream2);
+                       bt_notification_stream_begin_create(graph, src_stream2);
                assert(next_return.notification);
                break;
        case SEQ_STREAM1_END:
                next_return.notification =
-                       bt_notification_stream_end_create(src_stream1);
+                       bt_notification_stream_end_create(graph, src_stream1);
                assert(next_return.notification);
                break;
        case SEQ_STREAM2_END:
                next_return.notification =
-                       bt_notification_stream_end_create(src_stream2);
+                       bt_notification_stream_end_create(graph, src_stream2);
                assert(next_return.notification);
                break;
        case SEQ_STREAM1_PACKET1_BEGIN:
                next_return.notification =
-                       bt_notification_packet_begin_create(src_stream1_packet1);
+                       bt_notification_packet_begin_create(graph,
+                               src_stream1_packet1);
                assert(next_return.notification);
                break;
        case SEQ_STREAM1_PACKET2_BEGIN:
                next_return.notification =
-                       bt_notification_packet_begin_create(src_stream1_packet2);
+                       bt_notification_packet_begin_create(graph,
+                               src_stream1_packet2);
                assert(next_return.notification);
                break;
        case SEQ_STREAM2_PACKET1_BEGIN:
                next_return.notification =
-                       bt_notification_packet_begin_create(src_stream2_packet1);
+                       bt_notification_packet_begin_create(graph,
+                               src_stream2_packet1);
                assert(next_return.notification);
                break;
        case SEQ_STREAM2_PACKET2_BEGIN:
                next_return.notification =
-                       bt_notification_packet_begin_create(src_stream2_packet2);
+                       bt_notification_packet_begin_create(graph,
+                               src_stream2_packet2);
                assert(next_return.notification);
                break;
        case SEQ_STREAM1_PACKET1_END:
                next_return.notification =
-                       bt_notification_packet_end_create(src_stream1_packet1);
+                       bt_notification_packet_end_create(graph,
+                               src_stream1_packet1);
                assert(next_return.notification);
                break;
        case SEQ_STREAM1_PACKET2_END:
                next_return.notification =
-                       bt_notification_packet_end_create(src_stream1_packet2);
+                       bt_notification_packet_end_create(graph,
+                               src_stream1_packet2);
                assert(next_return.notification);
                break;
        case SEQ_STREAM2_PACKET1_END:
                next_return.notification =
-                       bt_notification_packet_end_create(src_stream2_packet1);
+                       bt_notification_packet_end_create(graph,
+                               src_stream2_packet1);
                assert(next_return.notification);
                break;
        case SEQ_STREAM2_PACKET2_END:
                next_return.notification =
-                       bt_notification_packet_end_create(src_stream2_packet2);
+                       bt_notification_packet_end_create(graph,
+                               src_stream2_packet2);
                assert(next_return.notification);
                break;
        case SEQ_EVENT_STREAM1_PACKET1:
@@ -502,9 +512,8 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq(
 
        if (event_packet) {
                next_return.notification =
-                       bt_notification_event_create(src_event_class,
-                       event_packet,
-                       src_empty_cc_prio_map);
+                       bt_notification_event_create(graph, src_event_class,
+                       event_packet, src_empty_cc_prio_map);
                assert(next_return.notification);
        }
 
@@ -777,12 +786,12 @@ void do_std_test(enum test test, const char *name,
        struct bt_component *sink_comp;
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
-       struct bt_graph *graph;
        enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
 
        clear_test_events();
        current_test = test;
        diag("test: %s", name);
+       assert(!graph);
        graph = bt_graph_create();
        assert(graph);
        create_source_sink(graph, &src_comp, &sink_comp);
@@ -813,7 +822,7 @@ void do_std_test(enum test test, const char *name,
 
        bt_put(src_comp);
        bt_put(sink_comp);
-       bt_put(graph);
+       BT_PUT(graph);
 }
 
 static
@@ -872,11 +881,11 @@ void test_output_port_notification_iterator(void)
        enum bt_notification_iterator_status iter_status =
                BT_NOTIFICATION_ITERATOR_STATUS_OK;
        struct bt_port *upstream_port;
-       struct bt_graph *graph;
 
        clear_test_events();
        current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
        diag("test: output port notification iterator");
+       assert(!graph);
        graph = bt_graph_create();
        assert(graph);
        create_source_sink(graph, &src_comp, NULL);
@@ -901,7 +910,7 @@ void test_output_port_notification_iterator(void)
                "the produced sequence of test events is the expected one");
 
        bt_put(src_comp);
-       bt_put(graph);
+       BT_PUT(graph);
        bt_put(notif_iter);
 }
 
@@ -911,11 +920,11 @@ void test_output_port_notification_iterator_cannot_consume(void)
        struct bt_component *src_comp;
        struct bt_notification_iterator *notif_iter;
        struct bt_port *upstream_port;
-       struct bt_graph *graph;
 
        clear_test_events();
        current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
        diag("test: cannot consume graph with existing output port notification iterator");
+       assert(!graph);
        graph = bt_graph_create();
        assert(graph);
        create_source_sink(graph, &src_comp, NULL);
@@ -935,7 +944,7 @@ void test_output_port_notification_iterator_cannot_consume(void)
                "bt_graph_run() returns BT_GRAPH_STATUS_CANNOT_CONSUME when there's an output port notification iterator");
 
        bt_put(src_comp);
-       bt_put(graph);
+       BT_PUT(graph);
        bt_put(notif_iter);
 }
 
index e83d6b09cba43d2ba19508bcc9d2312645a10239..185c6c2259c601c0e255acc1de4bb37009a0ca4b 100644 (file)
@@ -304,14 +304,12 @@ enum bt_component_status accept_port_connection(
        struct event event = {
                .type = COMP_ACCEPT_PORT_CONNECTION,
                .data.comp_accept_port_connection = {
-                       .comp = bt_component_from_private(private_component),
-                       .self_port = bt_port_from_private(self_private_port),
+                       .comp = bt_component_borrow_from_private(private_component),
+                       .self_port = bt_port_borrow_from_private(self_private_port),
                        .other_port = other_port,
                },
        };
 
-       bt_put(event.data.comp_accept_port_connection.comp);
-       bt_put(event.data.comp_accept_port_connection.self_port);
        append_event(&event);
        return BT_COMPONENT_STATUS_OK;
 }
@@ -326,14 +324,12 @@ void src_port_connected(struct bt_private_component *private_component,
        struct event event = {
                .type = COMP_PORT_CONNECTED,
                .data.comp_port_connected = {
-                       .comp = bt_component_from_private(private_component),
-                       .self_port = bt_port_from_private(self_private_port),
+                       .comp = bt_component_borrow_from_private(private_component),
+                       .self_port = bt_port_borrow_from_private(self_private_port),
                        .other_port = other_port,
                },
        };
 
-       bt_put(event.data.comp_port_connected.comp);
-       bt_put(event.data.comp_port_connected.self_port);
        append_event(&event);
 
        switch (current_test) {
@@ -355,13 +351,11 @@ void src_port_disconnected(struct bt_private_component *private_component,
        struct event event = {
                .type = COMP_PORT_DISCONNECTED,
                .data.comp_port_disconnected = {
-                       .comp = bt_component_from_private(private_component),
-                       .port = bt_port_from_private(private_port),
+                       .comp = bt_component_borrow_from_private(private_component),
+                       .port = bt_port_borrow_from_private(private_port),
                },
        };
 
-       bt_put(event.data.comp_port_disconnected.comp);
-       bt_put(event.data.comp_port_disconnected.port);
        append_event(&event);
 
        switch (current_test) {
@@ -417,14 +411,12 @@ void sink_port_connected(struct bt_private_component *private_component,
        struct event event = {
                .type = COMP_PORT_CONNECTED,
                .data.comp_port_connected = {
-                       .comp = bt_component_from_private(private_component),
-                       .self_port = bt_port_from_private(self_private_port),
+                       .comp = bt_component_borrow_from_private(private_component),
+                       .self_port = bt_port_borrow_from_private(self_private_port),
                        .other_port = other_port,
                },
        };
 
-       bt_put(event.data.comp_port_connected.comp);
-       bt_put(event.data.comp_port_connected.self_port);
        append_event(&event);
 }
 
@@ -435,13 +427,11 @@ void sink_port_disconnected(struct bt_private_component *private_component,
        struct event event = {
                .type = COMP_PORT_DISCONNECTED,
                .data.comp_port_disconnected = {
-                       .comp = bt_component_from_private(private_component),
-                       .port = bt_port_from_private(private_port),
+                       .comp = bt_component_borrow_from_private(private_component),
+                       .port = bt_port_borrow_from_private(private_port),
                },
        };
 
-       bt_put(event.data.comp_port_disconnected.comp);
-       bt_put(event.data.comp_port_disconnected.port);
        append_event(&event);
 }
 
index 27c905c588da30c65b73183689cb2b9319fdcb16..c02bbbef7d097837f9536c8157935ef6897bdc42 100644 (file)
@@ -72,6 +72,7 @@ struct graph_listener_data {
 static bool debug = false;
 static enum test current_test;
 static GArray *test_events;
+static struct bt_graph *graph;
 static struct bt_clock_class_priority_map *src_cc_prio_map;
 static struct bt_clock_class_priority_map *src_empty_cc_prio_map;
 static struct bt_clock_class *src_clock_class;
@@ -429,7 +430,7 @@ enum bt_notification_iterator_status src_iter_init(
 {
        struct src_iter_user_data *user_data =
                g_new0(struct src_iter_user_data, 1);
-       struct bt_port *port = bt_port_from_private(private_port);
+       struct bt_port *port = bt_port_borrow_from_private(private_port);
        const char *port_name;
        int ret;
 
@@ -441,7 +442,6 @@ enum bt_notification_iterator_status src_iter_init(
        port_name = bt_port_get_name(port);
        assert(port_name);
        user_data->iter_index = port_name[3] - '0';
-       bt_put(port);
 
        switch (user_data->iter_index) {
        case 0:
@@ -515,7 +515,7 @@ struct bt_notification *src_create_event_notif(struct bt_packet *packet,
        struct bt_clock_value *clock_value;
        struct bt_field *field;
 
-       notif = bt_notification_event_create(src_event_class,
+       notif = bt_notification_event_create(graph, src_event_class,
                packet, cc_prio_map);
        assert(notif);
        event = bt_notification_event_borrow_event(notif);
@@ -557,25 +557,27 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq(
                break;
        case SEQ_PACKET_BEGIN:
                next_return.notification =
-                       bt_notification_packet_begin_create(user_data->packet);
+                       bt_notification_packet_begin_create(graph,
+                               user_data->packet);
                assert(next_return.notification);
                break;
        case SEQ_PACKET_END:
                next_return.notification =
-                       bt_notification_packet_end_create(user_data->packet);
+                       bt_notification_packet_end_create(graph,
+                               user_data->packet);
                assert(next_return.notification);
                break;
        case SEQ_STREAM_BEGIN:
                stream = bt_packet_get_stream(user_data->packet);
                next_return.notification =
-                       bt_notification_stream_begin_create(stream);
+                       bt_notification_stream_begin_create(graph, stream);
                assert(next_return.notification);
                bt_put(stream);
                break;
        case SEQ_STREAM_END:
                stream = bt_packet_get_stream(user_data->packet);
                next_return.notification =
-                       bt_notification_stream_end_create(stream);
+                       bt_notification_stream_end_create(graph, stream);
                assert(next_return.notification);
                bt_put(stream);
                break;
@@ -620,13 +622,13 @@ struct bt_notification_iterator_next_method_return src_iter_next(
                                stream = bt_packet_get_stream(user_data->packet);
                                next_return.notification =
                                        bt_notification_stream_begin_create(
-                                               stream);
+                                               graph, stream);
                                bt_put(stream);
                                assert(next_return.notification);
                        } else if (user_data->at == 1) {
                                next_return.notification =
                                        bt_notification_packet_begin_create(
-                                               user_data->packet);
+                                               graph, user_data->packet);
                                assert(next_return.notification);
                        } else if (user_data->at < 7) {
                                next_return.notification =
@@ -637,13 +639,13 @@ struct bt_notification_iterator_next_method_return src_iter_next(
                        } else if (user_data->at == 7) {
                                next_return.notification =
                                        bt_notification_packet_end_create(
-                                               user_data->packet);
+                                               graph, user_data->packet);
                                assert(next_return.notification);
                        } else if (user_data->at == 8) {
                                stream = bt_packet_get_stream(user_data->packet);
                                next_return.notification =
                                        bt_notification_stream_end_create(
-                                               stream);
+                                               graph, stream);
                                bt_put(stream);
                                assert(next_return.notification);
                        } else {
@@ -991,7 +993,6 @@ void do_std_test(enum test test, const char *name,
        struct bt_component *sink_comp;
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
-       struct bt_graph *graph;
        int64_t i;
        int64_t count;
        enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
@@ -999,6 +1000,7 @@ void do_std_test(enum test test, const char *name,
        clear_test_events();
        current_test = test;
        diag("test: %s", name);
+       assert(!graph);
        graph = bt_graph_create();
        assert(graph);
        create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp);
@@ -1047,7 +1049,7 @@ void do_std_test(enum test test, const char *name,
        bt_put(src_comp);
        bt_put(muxer_comp);
        bt_put(sink_comp);
-       bt_put(graph);
+       BT_PUT(graph);
 }
 
 static
@@ -1406,7 +1408,6 @@ void test_single_end_then_multiple_full(void)
        struct bt_component *sink_comp;
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
-       struct bt_graph *graph;
        int64_t i;
        int64_t count;
        int ret;
@@ -1473,6 +1474,7 @@ void test_single_end_then_multiple_full(void)
        clear_test_events();
        current_test = TEST_SINGLE_END_THEN_MULTIPLE_FULL;
        diag("test: single end then multiple full");
+       assert(!graph);
        graph = bt_graph_create();
        assert(graph);
        create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp);
@@ -1522,7 +1524,7 @@ void test_single_end_then_multiple_full(void)
        bt_put(src_comp);
        bt_put(muxer_comp);
        bt_put(sink_comp);
-       bt_put(graph);
+       BT_PUT(graph);
 }
 
 static
@@ -1533,7 +1535,6 @@ void test_single_again_end_then_multiple_full(void)
        struct bt_component *sink_comp;
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
-       struct bt_graph *graph;
        int64_t i;
        int64_t count;
        int ret;
@@ -1601,6 +1602,7 @@ void test_single_again_end_then_multiple_full(void)
        clear_test_events();
        current_test = TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL;
        diag("test: single again then end then multiple full");
+       assert(!graph);
        graph = bt_graph_create();
        assert(graph);
        create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp);
@@ -1650,7 +1652,7 @@ void test_single_again_end_then_multiple_full(void)
        bt_put(src_comp);
        bt_put(muxer_comp);
        bt_put(sink_comp);
-       bt_put(graph);
+       BT_PUT(graph);
 }
 
 #define DEBUG_ENV_VAR  "TEST_UTILS_MUXER_DEBUG"
This page took 0.104333 seconds and 4 git commands to generate.