Skip to content

Commit

Permalink
lib: remove bt_graph_interrupt, add bt_graph_borrow_default_interrupter
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
simark authored and jgalar committed Jan 20, 2020
1 parent fecbdb3 commit f09b3ae
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/babeltrace2/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions src/bindings/python/bt2/bt2/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@ def add_interrupter(self, interrupter):
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)
5 changes: 2 additions & 3 deletions src/lib/graph/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/lib/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion tests/bindings/python/bt2/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def test_create_unknown_mip_version(self):
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):
Expand Down Expand Up @@ -321,7 +325,7 @@ def __init__(self, config, params, obj):
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):
Expand Down

0 comments on commit f09b3ae

Please sign in to comment.