lib: remove bt_graph_interrupt, add bt_graph_borrow_default_interrupter
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 16 Dec 2019 21:25:06 +0000 (16:25 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 17 Dec 2019 17:08:19 +0000 (17:08 +0000)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2708
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace2/graph/graph.h
src/bindings/python/bt2/bt2/graph.py
src/lib/graph/graph.c
src/lib/graph/graph.h
tests/bindings/python/bt2/test_graph.py

index 0a7484e475a854a9122e551fd9e32aa68824be57..0806509644bd7ddbb81d4d71cd5a277cd4bb3020 100644 (file)
@@ -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
 }
index a3926e5951ff14df902f47c5b5203281bad27cbd..9d5ba3aad42810979f7053f356d6ff3506ed6c65 100644 (file)
@@ -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)
index 70d00c3de1d70dd03d20576b8868cf4acd3d5a44..10080b953a22ef35979741fc832a130096109658 100644 (file)
@@ -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)
index dcc15260c6a2daef4f82a8d02c083c9ee794cffb..7e927e7a751131926b6f5215a7d6e2893ad636f3 100644 (file)
@@ -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;
 
index 3a52dd45a3850d09637324476598d51f3423a76c..f96c8d633c999e0379cb87d4ba8da426599836b8 100644 (file)
@@ -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):
This page took 0.031036 seconds and 4 git commands to generate.