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
25
26static 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}
ThreadVars * tv
SCThreadInitCallbackFn Callback
struct ThreadInitCallback_ * next
Per thread variable structure.
Definition threadvars.h:58
bool SCThreadRegisterInitCallback(SCThreadInitCallbackFn fn, void *user)
Register a thread init callback.
struct ThreadInitCallback_ ThreadInitCallback
void SCThreadRunInitCallbacks(ThreadVars *tv)
void(* SCThreadInitCallbackFn)(ThreadVars *tv, void *user)
Function type for thread intialization callbacks.
#define SCCalloc(nm, sz)
Definition util-mem.h:53