From 6c9552642393ae533624c310fc5970a02746b5c3 Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Wed, 14 Sep 2011 16:56:00 +0530 Subject: [PATCH] Introduce a new wrapper macro that wait loops till the flag(s) in question have been set --- src/counters.c | 8 ++------ src/cuda-packet-batcher.c | 4 +--- src/flow.c | 4 +--- src/tm-threads.c | 39 +++++++++++++++++++++------------------ src/tm-threads.h | 1 + src/util-mpm-b2g-cuda.c | 4 +--- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/counters.c b/src/counters.c index b2ef102c03..40436c2e9a 100644 --- a/src/counters.c +++ b/src/counters.c @@ -471,9 +471,7 @@ static void *SCPerfMgmtThread(void *arg) } } - while (!TmThreadsCheckFlag(tv_local, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv_local, THV_DEINIT); TmThreadsSetFlag(tv_local, THV_CLOSED); return NULL; @@ -543,9 +541,7 @@ static void *SCPerfWakeupThread(void *arg) } } - while (!TmThreadsCheckFlag(tv_local, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv_local, THV_DEINIT); TmThreadsSetFlag(tv_local, THV_CLOSED); return NULL; diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index cf8f9ba2b4..e4f103d0b0 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -372,9 +372,7 @@ void *SCCudaPBTmThreadsSlot1(void *td) } } - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); diff --git a/src/flow.c b/src/flow.c index a63d921593..c30ec1a5cc 100644 --- a/src/flow.c +++ b/src/flow.c @@ -1738,9 +1738,7 @@ void *FlowManagerThread(void *td) } } - while (!TmThreadsCheckFlag(th_v, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(th_v, THV_DEINIT); FlowHashDebugDeinit(); diff --git a/src/tm-threads.c b/src/tm-threads.c index c768317e95..25d6b0340b 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -177,9 +177,7 @@ void *TmThreadsSlot1NoIn(void *td) } } /* while (run) */ - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -251,9 +249,7 @@ void *TmThreadsSlot1NoOut(void *td) } } /* while (run) */ - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -320,9 +316,7 @@ void *TmThreadsSlot1NoInOut(void *td) } } /* while (run) */ - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -424,9 +418,7 @@ void *TmThreadsSlot1(void *td) } } /* while (run) */ - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data); @@ -581,9 +573,7 @@ void *TmThreadsSlotPktAcqLoop(void *td) { } SCPerfUpdateCounterArray(tv->sc_perf_pca, &tv->sc_perf_pctx, 0); - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); for (slot = s; slot != NULL; slot = slot->slot_next) { if (slot->SlotThreadExitPrintStats != NULL) { @@ -705,9 +695,7 @@ void *TmThreadsSlotVar(void *td) } /* while (run) */ SCPerfUpdateCounterArray(tv->sc_perf_pca, &tv->sc_perf_pctx, 0); - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); s = (TmSlot *)tv->tm_slots; @@ -1696,6 +1684,21 @@ void TmThreadTestThreadUnPaused(ThreadVars *tv) return; } +/** + * \brief Waits till the specified flag(s) is(are) set. We don't bother if + * the kill flag has been set or not on the thread. + * + * \param tv Pointer to the TV instance. + */ +void TmThreadWaitForFlag(ThreadVars *tv, uint8_t flags) +{ + while (!TmThreadsCheckFlag(tv, flags)) { + usleep(100); + } + + return; +} + /** * \brief Unpauses a thread * diff --git a/src/tm-threads.h b/src/tm-threads.h index af634a7f91..a802206653 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -111,6 +111,7 @@ ThreadVars *TmThreadsGetCallingThread(void); int TmThreadsCheckFlag(ThreadVars *, uint8_t); void TmThreadsSetFlag(ThreadVars *, uint8_t); void TmThreadsUnsetFlag(ThreadVars *, uint8_t); +void TmThreadWaitForFlag(ThreadVars *, uint8_t); TmEcode TmThreadsSlotVarRun (ThreadVars *tv, Packet *p, TmSlot *slot); diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index 83ec65c1a4..e42b244587 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -2269,9 +2269,7 @@ void *CudaMpmB2gThreadsSlot1(void *td) } } - while (!TmThreadsCheckFlag(tv, THV_DEINIT)) { - usleep(100); - } + TmThreadWaitForFlag(tv, THV_DEINIT); if (s->SlotThreadExitPrintStats != NULL) { s->SlotThreadExitPrintStats(tv, s->slot_data);