From 7492fb6a91b396533342fca6c98128f2f57fcfc3 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 10 Oct 2024 16:53:12 -0600 Subject: [PATCH] threads: merge unpause test into wait for pause function TmThreadTestThreadUnPaused was only being used by TmThreadsWaitForUnpause and is still enough to just become one function. --- src/tm-threads.c | 30 +++++++++++------------------- src/tm-threads.h | 7 +++++-- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/tm-threads.c b/src/tm-threads.c index ba086498f1..09bd040d71 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -358,11 +358,21 @@ error: return NULL; } +/** + * Also returns if the kill flag is set. + */ void TmThreadsWaitForUnpause(ThreadVars *tv) { if (TmThreadsCheckFlag(tv, THV_PAUSE)) { TmThreadsSetFlag(tv, THV_PAUSED); - TmThreadTestThreadUnPaused(tv); + + while (TmThreadsCheckFlag(tv, THV_PAUSE)) { + SleepUsec(100); + + if (TmThreadsCheckFlag(tv, THV_KILL)) + break; + } + TmThreadsUnsetFlag(tv, THV_PAUSED); } } @@ -1737,24 +1747,6 @@ static void TmThreadDeinitMC(ThreadVars *tv) } } -/** - * \brief Tests if the thread represented in the arg has been unpaused or not. - * - * The function would return if the thread tv has been unpaused or if the - * kill flag for the thread has been set. - * - * \param tv Pointer to the TV instance. - */ -void TmThreadTestThreadUnPaused(ThreadVars *tv) -{ - while (TmThreadsCheckFlag(tv, THV_PAUSE)) { - SleepUsec(100); - - if (TmThreadsCheckFlag(tv, THV_KILL)) - break; - } -} - /** * \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. diff --git a/src/tm-threads.h b/src/tm-threads.h index 2418fe99ba..2a46b133c4 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -108,7 +108,6 @@ void TmThreadSetPrio(ThreadVars *); int TmThreadGetNbThreads(uint8_t type); void TmThreadInitMC(ThreadVars *); -void TmThreadTestThreadUnPaused(ThreadVars *); void TmThreadContinue(ThreadVars *); void TmThreadContinueThreads(void); void TmThreadCheckThreadState(void); @@ -288,7 +287,11 @@ void TmThreadsGetMinimalTimestamp(struct timeval *ts); uint16_t TmThreadsGetWorkerThreadMax(void); bool TmThreadsTimeSubsysIsReady(void); -/** \brief Wait for a thread to become unpaused. */ +/** \brief Wait for a thread to become unpaused. + * + * Check if a thread should wait to be unpaused and wait if so, or + * until the thread kill flag is set. + */ void TmThreadsWaitForUnpause(ThreadVars *tv); #endif /* SURICATA_TM_THREADS_H */