2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 #ifndef BABELTRACE2_GRAPH_INTERRUPTER_H
8 #define BABELTRACE2_GRAPH_INTERRUPTER_H
10 #ifndef __BT_IN_BABELTRACE_H
11 # error "Please include <babeltrace2/babeltrace.h> instead."
14 #include <babeltrace2/types.h>
21 @defgroup api-intr Interrupter
27 An <strong><em>interrupter</em></strong> is a simple object which has
28 a single boolean state: set or not set.
30 You can use an interrupter to interrupt a running trace processing
31 \bt_graph or \ref api-qexec "query". The user and library functions periodically
32 check if they are interrupted (with
33 bt_self_component_sink_is_interrupted(),
34 bt_self_message_iterator_is_interrupted(), or
35 bt_query_executor_is_interrupted()); meanwhile, another thread or
36 a signal handler sets the shared interrupter with bt_interrupter_set().
38 To interrupt a running trace processing graph or query:
40 -# Create an interrupter with bt_interrupter_create().
42 -# Before running a trace processing graph with bt_graph_run() or
43 performing a query with bt_query_executor_query(), add
44 the created interrupter to the object with bt_graph_add_interrupter()
45 or bt_query_executor_add_interrupter().
47 Alternatively, you can borrow the existing, default interrupter from
48 those objects with bt_graph_borrow_default_interrupter() and
49 bt_query_executor_borrow_default_interrupter().
51 -# Run the graph with bt_graph_run() or perform the query with
52 bt_query_executor_query().
54 -# From a signal handler or another thread, call bt_interrupter_set() to
55 set the shared interrupter.
57 Eventually, the trace processing graph or query thread checks if it's
58 interrupted and stops processing, usually returning a status code which
61 You can add more than one interrupter to a trace processing graph and
62 to a query executor. The bt_self_component_sink_is_interrupted(),
63 bt_self_message_iterator_is_interrupted(), and
64 bt_query_executor_is_interrupted() functions return the logical
65 disjunction of all the added interrupters's states, so that \em any
66 interrupter can interrupt the thread.
68 Once a trace processing graph or a query executor is interrupted and
69 you get the thread's control back, you can reset the interrupter
70 with bt_interrupter_reset() and continue the previous operation,
71 calling bt_graph_run() or bt_query_executor_query() again.
73 An interrupter is a \ref api-fund-shared-object "shared object": get a
74 new reference with bt_interrupter_get_ref() and put an existing
75 reference with bt_interrupter_put_ref().
77 The type of an interrupter is #bt_interrupter.
86 @typedef struct bt_interrupter bt_interrupter;
101 Creates a default interrupter.
103 On success, the returned interrupter is \em not set
104 (bt_interrupter_is_set() returns #BT_FALSE).
107 New interrupter reference, or \c NULL on memory error.
109 extern bt_interrupter
*bt_interrupter_create(void);
120 Sets the interrupter \bt_p{interrupter}.
122 After you call this function, bt_interrupter_is_set() returns
125 @param[in] interrupter
128 @bt_pre_not_null{interrupter}
130 @sa bt_interrupter_reset() —
131 Resets an interrupter.
132 @sa bt_interrupter_is_set() —
133 Returns whether or not an interrupter is set.
135 extern void bt_interrupter_set(bt_interrupter
*interrupter
);
139 Resets the interrupter \bt_p{interrupter}.
141 After you call this function, bt_interrupter_is_set() returns
144 @param[in] interrupter
145 Interrupter to reset.
147 @bt_pre_not_null{interrupter}
149 @sa bt_interrupter_set() —
151 @sa bt_interrupter_is_set() —
152 Returns whether or not an interrupter is set.
154 extern void bt_interrupter_reset(bt_interrupter
*interrupter
);
158 Returns whether or not the interrupter \bt_p{interrupter} is set.
160 @param[in] interrupter
161 Interrupter to reset.
164 #BT_TRUE if \bt_p{interrupter} is set.
166 @bt_pre_not_null{interrupter}
168 @sa bt_interrupter_set() —
170 @sa bt_interrupter_reset() —
171 Resets an interrupter.
173 extern bt_bool
bt_interrupter_is_set(const bt_interrupter
*interrupter
);
178 @name Reference count
184 Increments the \ref api-fund-shared-object "reference count" of
185 the interrupter \bt_p{interrupter}.
187 @param[in] interrupter
189 Interrupter of which to increment the reference count.
194 @sa bt_interrupter_put_ref() —
195 Decrements the reference count of an interrupter.
197 extern void bt_interrupter_get_ref(const bt_interrupter
*interrupter
);
201 Decrements the \ref api-fund-shared-object "reference count" of
202 the interrupter \bt_p{interrupter}.
204 @param[in] interrupter
206 Interrupter of which to decrement the reference count.
211 @sa bt_interrupter_get_ref() —
212 Increments the reference count of an interrupter.
214 extern void bt_interrupter_put_ref(const bt_interrupter
*interrupter
);
218 Decrements the reference count of the interrupter
219 \bt_p{_interrupter}, and then sets \bt_p{_interrupter} to \c NULL.
223 Interrupter of which to decrement the reference count.
228 @bt_pre_assign_expr{_interrupter}
230 #define BT_INTERRUPTER_PUT_REF_AND_RESET(_interrupter) \
232 bt_interrupter_put_ref(_interrupter); \
233 (_interrupter) = NULL; \
238 Decrements the reference count of the interrupter \bt_p{_dst}, sets
239 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
241 This macro effectively moves an interrupter reference from the
242 expression \bt_p{_src} to the expression \bt_p{_dst}, putting the
243 existing \bt_p{_dst} reference.
247 Destination expression.
258 @bt_pre_assign_expr{_dst}
259 @bt_pre_assign_expr{_src}
261 #define BT_INTERRUPTER_MOVE_REF(_dst, _src) \
263 bt_interrupter_put_ref(_dst); \
276 #endif /* BABELTRACE2_GRAPH_INTERRUPTER_H */
This page took 0.034843 seconds and 4 git commands to generate.