]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: helper function TmThreadsWaitForUnpause
authorJason Ish <jason.ish@oisf.net>
Wed, 9 Oct 2024 23:24:09 +0000 (17:24 -0600)
committerVictor Julien <victor@inliniac.net>
Sat, 12 Oct 2024 09:03:39 +0000 (11:03 +0200)
The pattern of checking the pause flag, setting to paused then
waiting to unpause was done enough times to factor out into its own
function. This is also needed by library users who bring their own
packet acquisition threads.

src/counters.c
src/detect-engine-loader.c
src/flow-bypass.c
src/flow-manager.c
src/tm-threads.c
src/tm-threads.h

index 7d141efb0144875ce883bf57346287babb4dd932..ae0f302b9e84af7f142c03c893748884d8d2fb74 100644 (file)
@@ -407,11 +407,7 @@ static void *StatsMgmtThread(void *arg)
 
     TmThreadsSetFlag(tv_local, THV_INIT_DONE | THV_RUNNING);
     while (1) {
-        if (TmThreadsCheckFlag(tv_local, THV_PAUSE)) {
-            TmThreadsSetFlag(tv_local, THV_PAUSED);
-            TmThreadTestThreadUnPaused(tv_local);
-            TmThreadsUnsetFlag(tv_local, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(tv_local);
 
         struct timeval cur_timev;
         gettimeofday(&cur_timev, NULL);
@@ -489,11 +485,7 @@ static void *StatsWakeupThread(void *arg)
     TmThreadsSetFlag(tv_local, THV_INIT_DONE | THV_RUNNING);
 
     while (1) {
-        if (TmThreadsCheckFlag(tv_local, THV_PAUSE)) {
-            TmThreadsSetFlag(tv_local, THV_PAUSED);
-            TmThreadTestThreadUnPaused(tv_local);
-            TmThreadsUnsetFlag(tv_local, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(tv_local);
 
         struct timeval cur_timev;
         gettimeofday(&cur_timev, NULL);
index fba39e087992f94cd7a68ed78f8173fc9a8d96eb..6f588deb07cfec62141b311685e0d95d701ecf71 100644 (file)
@@ -597,11 +597,7 @@ static TmEcode DetectLoader(ThreadVars *th_v, void *thread_data)
     SCLogDebug("loader thread started");
     while (1)
     {
-        if (TmThreadsCheckFlag(th_v, THV_PAUSE)) {
-            TmThreadsSetFlag(th_v, THV_PAUSED);
-            TmThreadTestThreadUnPaused(th_v);
-            TmThreadsUnsetFlag(th_v, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(th_v);
 
         /* see if we have tasks */
 
index 10ecf91f494e7e26e66f49d44390af9a7c90c832..3e0123c8101a56fc886c1f31526040a7272a9723 100644 (file)
@@ -96,11 +96,7 @@ static TmEcode BypassedFlowManager(ThreadVars *th_v, void *thread_data)
     TmThreadsSetFlag(th_v, THV_RUNNING);
 
     while (1) {
-        if (TmThreadsCheckFlag(th_v, THV_PAUSE)) {
-            TmThreadsSetFlag(th_v, THV_PAUSED);
-            TmThreadTestThreadUnPaused(th_v);
-            TmThreadsUnsetFlag(th_v, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(th_v);
         SCLogDebug("Dumping the table");
         gettimeofday(&tv, NULL);
         TIMEVAL_TO_TIMESPEC(&tv, &curtime);
index 15abaa40b29fb168140047aced93ed01c3f48571..9448450416ed2ce66bfa3e6c0fb4dcdc5aa4348e 100644 (file)
@@ -820,11 +820,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
 
     while (1)
     {
-        if (TmThreadsCheckFlag(th_v, THV_PAUSE)) {
-            TmThreadsSetFlag(th_v, THV_PAUSED);
-            TmThreadTestThreadUnPaused(th_v);
-            TmThreadsUnsetFlag(th_v, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(th_v);
 
         bool emerg = ((SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) != 0);
 
@@ -1085,11 +1081,7 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
 
     while (1)
     {
-        if (TmThreadsCheckFlag(th_v, THV_PAUSE)) {
-            TmThreadsSetFlag(th_v, THV_PAUSED);
-            TmThreadTestThreadUnPaused(th_v);
-            TmThreadsUnsetFlag(th_v, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(th_v);
         SC_ATOMIC_ADD(flowrec_busy,1);
         FlowQueuePrivate list = FlowQueueExtractPrivate(&flow_recycle_q);
 
index 2c01bd60397458c20f74307cba5cd8c00c416b72..ba086498f1af93c8d9968b7449d53d87056af110 100644 (file)
@@ -305,11 +305,7 @@ static void *TmThreadsSlotPktAcqLoop(void *td)
     TmThreadsSetFlag(tv, THV_INIT_DONE);
 
     while(run) {
-        if (TmThreadsCheckFlag(tv, THV_PAUSE)) {
-            TmThreadsSetFlag(tv, THV_PAUSED);
-            TmThreadTestThreadUnPaused(tv);
-            TmThreadsUnsetFlag(tv, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(tv);
 
         r = s->PktAcqLoop(tv, SC_ATOMIC_GET(s->slot_data), s);
 
@@ -362,6 +358,15 @@ error:
     return NULL;
 }
 
+void TmThreadsWaitForUnpause(ThreadVars *tv)
+{
+    if (TmThreadsCheckFlag(tv, THV_PAUSE)) {
+        TmThreadsSetFlag(tv, THV_PAUSED);
+        TmThreadTestThreadUnPaused(tv);
+        TmThreadsUnsetFlag(tv, THV_PAUSED);
+    }
+}
+
 static void *TmThreadsSlotVar(void *td)
 {
     ThreadVars *tv = (ThreadVars *)td;
@@ -442,11 +447,7 @@ static void *TmThreadsSlotVar(void *td)
     s = (TmSlot *)tv->tm_slots;
 
     while (run) {
-        if (TmThreadsCheckFlag(tv, THV_PAUSE)) {
-            TmThreadsSetFlag(tv, THV_PAUSED);
-            TmThreadTestThreadUnPaused(tv);
-            TmThreadsUnsetFlag(tv, THV_PAUSED);
-        }
+        TmThreadsWaitForUnpause(tv);
 
         /* input a packet */
         p = tv->tmqh_in(tv);
index 67bea14110328dcc2b5cf475d51bed047d9dfe95..2418fe99ba35175f0b5864cbcc9c0f98af01fbe1 100644 (file)
@@ -288,4 +288,7 @@ void TmThreadsGetMinimalTimestamp(struct timeval *ts);
 uint16_t TmThreadsGetWorkerThreadMax(void);
 bool TmThreadsTimeSubsysIsReady(void);
 
+/** \brief Wait for a thread to become unpaused. */
+void TmThreadsWaitForUnpause(ThreadVars *tv);
+
 #endif /* SURICATA_TM_THREADS_H */