From f09b3ae994955a5f6a2baca18091ed5f7d035183 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 16 Dec 2019 16:25:06 -0500 Subject: [PATCH] lib: remove bt_graph_interrupt, add bt_graph_borrow_default_interrupter It is currently possible to interrupt a running graph with bt_graph_interrupt. It is however not possible to reset the default interrupter that this function sets and resume the graph execution. Rather than add a new graph function to reset the default graph interrupter, introduce a new function, bt_graph_borrow_default_interrupter, to borrow that default interrupter. All the bt_interrupter API is therefore accessible with this default interrupter. This patch removes the bt_graph_interrupt function, since it's no longer needed. Change-Id: I277e6c8bb4e1be0a6557a6287b7ba8997e20d27b Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2708 Tested-by: jenkins Reviewed-by: Philippe Proulx --- include/babeltrace2/graph/graph.h | 2 +- src/bindings/python/bt2/bt2/graph.py | 6 ++++-- src/lib/graph/graph.c | 5 ++--- src/lib/graph/graph.h | 3 +-- tests/bindings/python/bt2/test_graph.py | 6 +++++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/babeltrace2/graph/graph.h b/include/babeltrace2/graph/graph.h index 0a7484e4..08065096 100644 --- a/include/babeltrace2/graph/graph.h +++ b/include/babeltrace2/graph/graph.h @@ -240,7 +240,7 @@ typedef enum bt_graph_add_interrupter_status { extern bt_graph_add_interrupter_status bt_graph_add_interrupter(bt_graph *graph, const bt_interrupter *interrupter); -extern void bt_graph_interrupt(bt_graph *graph); +extern bt_interrupter *bt_graph_borrow_default_interrupter(bt_graph *graph); #ifdef __cplusplus } diff --git a/src/bindings/python/bt2/bt2/graph.py b/src/bindings/python/bt2/bt2/graph.py index a3926e59..9d5ba3aa 100644 --- a/src/bindings/python/bt2/bt2/graph.py +++ b/src/bindings/python/bt2/bt2/graph.py @@ -159,5 +159,7 @@ class Graph(object._SharedObject): utils._check_type(interrupter, bt2_interrupter.Interrupter) native_bt.graph_add_interrupter(self._ptr, interrupter._ptr) - def interrupt(self): - native_bt.graph_interrupt(self._ptr) + @property + def default_interrupter(self): + ptr = native_bt.graph_borrow_default_interrupter(self._ptr) + return bt2_interrupter.Interrupter._create_from_ptr_and_get_ref(ptr) diff --git a/src/lib/graph/graph.c b/src/lib/graph/graph.c index 70d00c3d..10080b95 100644 --- a/src/lib/graph/graph.c +++ b/src/lib/graph/graph.c @@ -1194,11 +1194,10 @@ enum bt_graph_add_interrupter_status bt_graph_add_interrupter( return BT_FUNC_STATUS_OK; } -void bt_graph_interrupt(struct bt_graph *graph) +struct bt_interrupter *bt_graph_borrow_default_interrupter(bt_graph *graph) { BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - bt_interrupter_set(graph->default_interrupter); - BT_LIB_LOGI("Interrupted graph: %!+g", graph); + return graph->default_interrupter; } void bt_graph_get_ref(const struct bt_graph *graph) diff --git a/src/lib/graph/graph.h b/src/lib/graph/graph.h index dcc15260..7e927e7a 100644 --- a/src/lib/graph/graph.h +++ b/src/lib/graph/graph.h @@ -101,8 +101,7 @@ struct bt_graph { GPtrArray *interrupters; /* - * Default interrupter to support bt_graph_interrupt(); owned - * by this. + * Default interrupter, owned by this. */ struct bt_interrupter *default_interrupter; diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 3a52dd45..f96c8d63 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -65,6 +65,10 @@ class GraphTestCase(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'unknown MIP version'): bt2.Graph(1) + def test_default_interrupter(self): + interrupter = self._graph.default_interrupter + self.assertIs(type(interrupter), bt2.Interrupter) + def test_add_component_user_cls(self): class MySink(bt2._UserSinkComponent): def _user_consume(self): @@ -321,7 +325,7 @@ class GraphTestCase(unittest.TestCase): def _user_consume(self): # Pretend that somebody asynchronously interrupted the graph. nonlocal graph - graph.interrupt() + graph.default_interrupter.set() return next(self._msg_iter) def _user_graph_is_configured(self): -- 2.34.1