File tree Expand file tree Collapse file tree
doc/userguide/devguide/extending Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ Extending Suricata
1212 output/index.rst
1313 output/eve-filetypes.rst
1414 output/eve-hooks.rst
15+ threads.rst
1516 flow-lifecycle-callbacks.rst
Original file line number Diff line number Diff line change 1+ Threads
2+ #######
3+
4+ Rust API
5+ ********
6+
7+ The ``suricata_ffi::thread `` module provides Rust wrappers for thread
8+ lifecycle callbacks.
9+
10+ Thread Init Callback
11+ ====================
12+
13+ Register a callback with ``thread::register_init_callback `` to run code for
14+ each Suricata thread as it is initialized. The callback receives a raw
15+ ``ThreadVars `` pointer for the thread that has just been initialized.
16+
17+ The current Rust thread lifecycle API exposes an init callback only; there is
18+ no Rust thread deinit callback.
19+
20+ .. code-block :: rust
21+
22+ use suricata_ffi::thread;
23+ use suricata_ffi::SCLogNotice;
24+ use suricata_sys::sys::ThreadVars;
25+
26+ fn on_thread_init(tv: *mut ThreadVars) {
27+ SCLogNotice!("thread initialized: {:p}", tv);
28+ }
29+
30+ fn register_thread_callbacks() -> Result<(), &'static str> {
31+ thread::register_init_callback(on_thread_init)
32+ }
33+
34+ The wrapper accepts function items or closures that implement
35+ ``Fn(*mut ThreadVars) + Send + Sync + 'static `` and returns
36+ ``Result<(), &'static str> ``. An error means the callback could not be
37+ registered. Registered callbacks are kept for the Suricata process lifetime.
38+
39+ The ``ThreadVars `` pointer is only valid for the duration of the callback
40+ invocation and must not be stored. Rust callbacks must not panic.
You can’t perform that action at this time.
0 commit comments