Collect useless graph's connections
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 13 May 2017 17:17:45 +0000 (13:17 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:43 +0000 (12:57 -0400)
commitf167d3c0c0904ef36e19fcd37f4f20d33b0e76b6
tree25f835a5dce01675e0ee4d2580f886b62d2a9365
parent087bc0603db40d8cd5f4fddf933f3ded4829369e
Collect useless graph's connections

Before this patch, the connections accumulate in the graph's array of
connections and are never destroyed until the graph is destroyed.
However, because it is possible to disconnect the ports of a connection,
it is possible that a graph contains connections that are useless. This
can cause a "leak" of connections, which would be especially experienced
with a graph that contains a source which dynamically adds and removes
many ports that are connected during its lifetime.

The conditions for a connection to be considered useless are:

1. Its reference count is 0. This means only its parent, the graph,
   controls its existence.
2. Its ports are disconnected.
3. All its created notification iterators are finalized.

When all the conditions above are satisfied, it is safe to remove the
connection from its parent graph.

Conditions 2 and 3 can be checked in:

* bt_connection_disconnect_ports(): The connection is dead, detached
  from its ports, and vice versa, thus satisfying condition 2.
* bt_connection_remove_iterator(): The number of notification iterators
  changes; could drop to 0, thus satisfying condition 3.

To accomodate condition 1, a new concept is added to the base object: it
is possible to set a "parent is owner" listener which is called when the
parent becomes the owner of the object (that is, when the object's
reference count drops to 0 and it has a parent). Connection objects use
this callback to possibly remove itself from its parent when all three
conditions above are satisfied.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/graph/graph-internal.h
include/babeltrace/object-internal.h
lib/graph/connection.c
lib/graph/graph.c
This page took 0.025437 seconds and 4 git commands to generate.