Skip to content

Commit

Permalink
lib: remove bt_query_executor_interrupt, add bt_query_executor_borrow…
Browse files Browse the repository at this point in the history
…_default_interrupter

It is currently possible to interrupt a running quer executor with
bt_query_executor_interrupt.  It is however not possible to reset the
default interrupter that this function sets and resume the query
execution.

Rather than add a new query executor function to reset the default query
executor interrupter, introduce a new function,
bt_query_executor_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_query_executor_interrupt function, since it's
no longer needed.

Change-Id: I877dfbf22e36233750a71220fc5ab0297f8c0c28
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2709
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 f09b3ae commit d9a20b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/babeltrace2/graph/query-executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ extern bt_query_executor_add_interrupter_status
bt_query_executor_add_interrupter(bt_query_executor *query_executor,
const bt_interrupter *interrupter);

extern void bt_query_executor_interrupt(bt_query_executor *query_executor);
extern bt_interrupter *bt_query_executor_borrow_default_interrupter(
bt_query_executor *query_executor);

typedef enum bt_query_executor_set_logging_level_status {
BT_QUERY_EXECUTOR_SET_LOGGING_LEVEL_STATUS_OK = __BT_FUNC_STATUS_OK,
Expand Down
6 changes: 4 additions & 2 deletions src/bindings/python/bt2/bt2/query_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def add_interrupter(self, interrupter):
utils._check_type(interrupter, bt2_interrupter.Interrupter)
native_bt.query_executor_add_interrupter(self._ptr, interrupter._ptr)

def interrupt(self):
native_bt.query_executor_interrupt(self._ptr)
@property
def default_interrupter(self):
ptr = native_bt.query_executor_borrow_default_interrupter(self._ptr)
return bt2_interrupter.Interrupter._create_from_ptr_and_get_ref(ptr)

def _set_logging_level(self, log_level):
utils._check_log_level(log_level)
Expand Down
7 changes: 3 additions & 4 deletions src/lib/graph/query-executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,11 @@ bt_bool bt_query_executor_is_interrupted(const struct bt_query_executor *query_e
query_exec->interrupters);
}

void bt_query_executor_interrupt(struct bt_query_executor *query_exec)
struct bt_interrupter *bt_query_executor_borrow_default_interrupter(
struct bt_query_executor *query_exec)
{
BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
bt_interrupter_set(query_exec->default_interrupter);
BT_LIB_LOGI("Interrupted query executor: query-exec-addr=%p",
query_exec);
return query_exec->default_interrupter;
}

enum bt_query_executor_set_logging_level_status
Expand Down
11 changes: 10 additions & 1 deletion tests/bindings/python/bt2/test_query_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@


class QueryExecutorTestCase(unittest.TestCase):
def test_default_interrupter(self):
class MySink(bt2._UserSinkComponent):
def _user_consume(self):
pass

query_exec = bt2.QueryExecutor(MySink, 'obj')
interrupter = query_exec.default_interrupter
self.assertIs(type(interrupter), bt2.Interrupter)

def test_query(self):
class MySink(bt2._UserSinkComponent):
def _user_consume(self):
Expand Down Expand Up @@ -262,7 +271,7 @@ def _user_consume(self):
@classmethod
def _user_query(cls, priv_query_exec, obj, params, method_obj):
test_self.assertFalse(query_exec.is_interrupted)
query_exec.interrupt()
query_exec.default_interrupter.set()
test_self.assertTrue(query_exec.is_interrupted)

test_self = self
Expand Down

0 comments on commit d9a20b2

Please sign in to comment.