suricata
thread-callbacks.c
Go to the documentation of this file.
1 /* Copyright (C) 2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "thread-callbacks.h"
19 
20 typedef struct ThreadInitCallback_ {
22  void *user;
25 
26 static ThreadInitCallback *init_callbacks = NULL;
27 
29 {
30  ThreadInitCallback *cb = SCCalloc(1, sizeof(*cb));
31  if (cb == NULL) {
32  return false;
33  }
34  cb->Callback = fn;
35  cb->user = user;
36  if (init_callbacks == NULL) {
37  init_callbacks = cb;
38  } else {
39  ThreadInitCallback *current = init_callbacks;
40  while (current->next != NULL) {
41  current = current->next;
42  }
43  current->next = cb;
44  }
45  return true;
46 }
47 
49 {
50  ThreadInitCallback *cb = init_callbacks;
51  while (cb != NULL) {
52  cb->Callback(tv, cb->user);
53  cb = cb->next;
54  }
55 }
SCThreadRegisterInitCallback
bool SCThreadRegisterInitCallback(SCThreadInitCallbackFn fn, void *user)
Register a thread init callback.
Definition: thread-callbacks.c:28
thread-callbacks.h
ThreadInitCallback_
Definition: thread-callbacks.c:20
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
ThreadInitCallback_::next
struct ThreadInitCallback_ * next
Definition: thread-callbacks.c:23
ThreadInitCallback
struct ThreadInitCallback_ ThreadInitCallback
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
SCThreadRunInitCallbacks
void SCThreadRunInitCallbacks(ThreadVars *tv)
Definition: thread-callbacks.c:48
SCThreadInitCallbackFn
void(* SCThreadInitCallbackFn)(ThreadVars *tv, void *user)
Function type for thread intialization callbacks.
Definition: thread-callbacks.h:33
ThreadInitCallback_::Callback
SCThreadInitCallbackFn Callback
Definition: thread-callbacks.c:21
ThreadInitCallback_::user
void * user
Definition: thread-callbacks.c:22
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53