Skip to content

Commit

Permalink
detect/loader: minor code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
victorjulien committed Aug 11, 2023
1 parent a4f6706 commit f312370
Showing 1 changed file with 17 additions and 40 deletions.
57 changes: 17 additions & 40 deletions src/detect-engine-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
#define NLOADERS 4
static DetectLoaderControl *loaders = NULL;
static int cur_loader = 0;
void TmThreadWakeupDetectLoaderThreads(void);
static void TmThreadWakeupDetectLoaderThreads(void);
static int num_loaders = NLOADERS;

/** \param loader -1 for auto select
Expand Down Expand Up @@ -427,14 +427,14 @@ int DetectLoadersSync(void)
{
SCLogDebug("waiting");
int errors = 0;
int i;
for (i = 0; i < num_loaders; i++) {
int done = 0;
for (int i = 0; i < num_loaders; i++) {
bool done = false;

DetectLoaderControl *loader = &loaders[i];
while (!done) {
SCMutexLock(&loader->m);
if (TAILQ_EMPTY(&loader->task_list)) {
done = 1;
done = true;
}
SCMutexUnlock(&loader->m);
}
Expand All @@ -444,7 +444,6 @@ int DetectLoadersSync(void)
loader->result = 0;
}
SCMutexUnlock(&loader->m);

}
if (errors) {
SCLogError("%d loaders reported errors", errors);
Expand All @@ -467,34 +466,29 @@ void DetectLoadersInit(void)
(void)ConfGetInt("multi-detect.loaders", &setting);

if (setting < 1 || setting > 1024) {
SCLogError("invalid multi-detect.loaders setting %" PRIdMAX, setting);
exit(EXIT_FAILURE);
FatalError("invalid multi-detect.loaders setting %" PRIdMAX, setting);
}
num_loaders = (int32_t)setting;

num_loaders = (int32_t)setting;
SCLogInfo("using %d detect loader threads", num_loaders);

BUG_ON(loaders != NULL);
loaders = SCCalloc(num_loaders, sizeof(DetectLoaderControl));
BUG_ON(loaders == NULL);

int i;
for (i = 0; i < num_loaders; i++) {
for (int i = 0; i < num_loaders; i++) {
DetectLoaderInit(&loaders[i]);
}
}

/**
* \brief Unpauses all threads present in tv_root
*/
void TmThreadWakeupDetectLoaderThreads(void)
static void TmThreadWakeupDetectLoaderThreads(void)
{
ThreadVars *tv = NULL;
int i = 0;

SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) {
tv = tv_root[i];
for (int i = 0; i < TVT_MAX; i++) {
ThreadVars *tv = tv_root[i];
while (tv != NULL) {
if (strncmp(tv->name,"DL#",3) == 0) {
BUG_ON(tv->ctrl_cond == NULL);
Expand All @@ -504,21 +498,16 @@ void TmThreadWakeupDetectLoaderThreads(void)
}
}
SCMutexUnlock(&tv_root_lock);

return;
}

/**
* \brief Unpauses all threads present in tv_root
*/
void TmThreadContinueDetectLoaderThreads(void)
{
ThreadVars *tv = NULL;
int i = 0;

SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) {
tv = tv_root[i];
for (int i = 0; i < TVT_MAX; i++) {
ThreadVars *tv = tv_root[i];
while (tv != NULL) {
if (strncmp(tv->name,"DL#",3) == 0)
TmThreadContinue(tv);
Expand All @@ -527,11 +516,8 @@ void TmThreadContinueDetectLoaderThreads(void)
}
}
SCMutexUnlock(&tv_root_lock);

return;
}


SC_ATOMIC_DECLARE(int, detect_loader_cnt);

typedef struct DetectLoaderThreadData_ {
Expand Down Expand Up @@ -613,27 +599,18 @@ static TmEcode DetectLoader(ThreadVars *th_v, void *thread_data)
/** \brief spawn the detect loader manager thread */
void DetectLoaderThreadSpawn(void)
{
int i;
for (i = 0; i < num_loaders; i++) {
ThreadVars *tv_loader = NULL;

for (int i = 0; i < num_loaders; i++) {
char name[TM_THREAD_NAME_MAX];
snprintf(name, sizeof(name), "%s#%02d", thread_name_detect_loader, i+1);

tv_loader = TmThreadCreateCmdThreadByName(name,
"DetectLoader", 1);
BUG_ON(tv_loader == NULL);

ThreadVars *tv_loader = TmThreadCreateCmdThreadByName(name, "DetectLoader", 1);
if (tv_loader == NULL) {
printf("ERROR: TmThreadsCreate failed\n");
exit(1);
FatalError("failed to create thread %s", name);
}
if (TmThreadSpawn(tv_loader) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(1);
FatalError("failed to create spawn %s", name);
}
}
return;
}

void TmModuleDetectLoaderRegister (void)
Expand Down

0 comments on commit f312370

Please sign in to comment.