TmThreadsManagement
static void *TmThreadsManagement(void *td)
{
UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots;
TmEcode r = TM_ECODE_OK;
BUG_ON(s == NULL);
if (SCSetThreadName(tv->name) < 0) {
SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name");
}
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
SCDropCaps(tv);
SCLogDebug("%s starting", tv->name);
if (s->SlotThreadInit != NULL) {
void *slot_data = NULL;
r = s->SlotThreadInit(tv, s->slot_initdata, &slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
pthread_exit((void *) -1);
return NULL;
}
(void)SC_ATOMIC_SET(s->slot_data, slot_data);
}
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
StatsSetupPrivate(tv);
TmThreadsSetFlag(tv, THV_INIT_DONE);
r = s->Management(tv, SC_ATOMIC_GET(s->slot_data));
if (r == TM_ECODE_FAILED) {
TmThreadsSetFlag(tv, THV_FAILED);
}
if (TmThreadsCheckFlag(tv, THV_KILL)) {
StatsSyncCounters(tv);
}
TmThreadsSetFlag(tv, THV_RUNNING_DONE);
TmThreadWaitForFlag(tv, THV_DEINIT);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, SC_ATOMIC_GET(s->slot_data));
}
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, SC_ATOMIC_GET(s->slot_data));
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
return NULL;
}
}
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) 0);
return NULL;
}