diff --git a/src/counters.c b/src/counters.c index 45ecd2d0c0..b2ef102c03 100644 --- a/src/counters.c +++ b/src/counters.c @@ -471,6 +471,10 @@ static void *SCPerfMgmtThread(void *arg) } } + while (!TmThreadsCheckFlag(tv_local, THV_DEINIT)) { + usleep(100); + } + TmThreadsSetFlag(tv_local, THV_CLOSED); return NULL; } @@ -535,11 +539,15 @@ static void *SCPerfWakeupThread(void *arg) } if (TmThreadsCheckFlag(tv_local, THV_KILL)) { - TmThreadsSetFlag(tv_local, THV_CLOSED); run = 0; } } + while (!TmThreadsCheckFlag(tv_local, THV_DEINIT)) { + usleep(100); + } + + TmThreadsSetFlag(tv_local, THV_CLOSED); return NULL; } diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index 8eb98f6b10..cf8f9ba2b4 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -372,6 +372,10 @@ void *SCCudaPBTmThreadsSlot1(void *td) } } + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); } diff --git a/src/flow.c b/src/flow.c index 8d63abdf18..a63d921593 100644 --- a/src/flow.c +++ b/src/flow.c @@ -1486,6 +1486,7 @@ void FlowForceReassembly(void) } TmThreadsSetFlag(tv, THV_KILL); + TmThreadsSetFlag(tv, THV_DEINIT); /* be sure it has shut down */ while (!TmThreadsCheckFlag(tv, THV_CLOSED)) { @@ -1737,6 +1738,10 @@ void *FlowManagerThread(void *td) } } + while (!TmThreadsCheckFlag(th_v, THV_DEINIT)) { + usleep(100); + } + FlowHashDebugDeinit(); SCLogInfo("%" PRIu32 " new flows, %" PRIu32 " established flows were " diff --git a/src/threadvars.h b/src/threadvars.h index 87da5ccfeb..7b3546fae1 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -39,6 +39,9 @@ struct TmSlot_; #define THV_KILL 0x08 /** thread has been asked to cleanup and exit */ #define THV_FAILED 0x10 /** thread has encountered an error and failed */ #define THV_CLOSED 0x20 /** thread done, should be joinable */ +/* used to indicate the thread is going through de-init. Introduced as more + * of a hack for solving stream-timeout-shutdown. Is set by the main thread. */ +#define THV_DEINIT 0x40 /** Thread flags set and read by threads, to control the threads, when they * encounter certain conditions like failure */ diff --git a/src/tm-threads.c b/src/tm-threads.c index 6bf69bd47a..da9e9c19b5 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -177,9 +177,13 @@ void *TmThreadsSlot1NoIn(void *td) } } /* while (run) */ + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + /* wait for synchronization from master, if this TV has a synchronization * point set by this name */ - TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); + //TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -251,9 +255,13 @@ void *TmThreadsSlot1NoOut(void *td) } } /* while (run) */ + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + /* wait for synchronization from master, if this TV has a synchronization * point set by this name */ - TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); + //TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -320,9 +328,13 @@ void *TmThreadsSlot1NoInOut(void *td) } } /* while (run) */ + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + /* wait for synchronization from master, if this TV has a synchronization * point set by this name */ - TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); + //TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -424,9 +436,13 @@ void *TmThreadsSlot1(void *td) } } /* while (run) */ + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + /* wait for synchronization from master, if this TV has a synchronization * point set by this name */ - TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); + //TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -581,9 +597,13 @@ void *TmThreadsSlotPktAcqLoop(void *td) { } SCPerfUpdateCounterArray(tv->sc_perf_pca, &tv->sc_perf_pctx, 0); + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + /* wait for synchronization from master, if this TV has a synchronization * point set by this name */ - TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); + //TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); for (slot = s; slot != NULL; slot = slot->slot_next) { if (slot->SlotThreadExitPrintStats != NULL) { @@ -705,9 +725,13 @@ void *TmThreadsSlotVar(void *td) } /* while (run) */ SCPerfUpdateCounterArray(tv->sc_perf_pca, &tv->sc_perf_pctx, 0); + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + /* wait for synchronization from master, if this TV has a synchronization * point set by this name */ - TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); + //TmThreadsMSSlaveHitSyncPt(tv, "ReceiveTMBeforeDeInit"); s = (TmSlot *)tv->tm_slots; @@ -1376,6 +1400,7 @@ void TmThreadKillThread(ThreadVars *tv) /* set the thread flag informing the thread that it needs to be * terminated */ TmThreadsSetFlag(tv, THV_KILL); + TmThreadsSetFlag(tv, THV_DEINIT); if (tv->inq != NULL) { /* signal the queue for the number of users */ @@ -1510,9 +1535,10 @@ void TmThreadKillThreads(void) { } TmThreadsSetFlag(tv, THV_KILL); + TmThreadsSetFlag(tv, THV_DEINIT); SCLogDebug("told thread %s to stop", tv->name); - TmThreadsMSMasterDisableSlaveAllSyncPts(tv); + //TmThreadsMSMasterDisableSlaveAllSyncPts(tv); if (tv->inq != NULL) { int i; diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index d8c6e19f9a..83ec65c1a4 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -2269,6 +2269,10 @@ void *CudaMpmB2gThreadsSlot1(void *td) } } + while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { + usleep(100); + } + if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); }