From 1957c46efc0814efc16ee0677994696dde08ced7 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 27 Apr 2022 17:21:25 +0200 Subject: [PATCH] threads: remove usused code; wrap in guards --- src/tm-modules.c | 2 + src/tm-modules.h | 3 +- src/tm-threads.c | 145 +++-------------------------------------------- src/tm-threads.h | 7 --- 4 files changed, 11 insertions(+), 146 deletions(-) diff --git a/src/tm-modules.c b/src/tm-modules.c index 354770057e..bbf11b3156 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -189,6 +189,7 @@ void TmModuleRegisterTests(void) #endif /* UNITTESTS */ } +#ifdef PROFILING #define CASE_CODE(E) case E: return #E /** @@ -246,3 +247,4 @@ const char * TmModuleTmmIdToString(TmmId id) } return ""; } +#endif diff --git a/src/tm-modules.h b/src/tm-modules.h index 7df5b91be3..7b697f2ec4 100644 --- a/src/tm-modules.h +++ b/src/tm-modules.h @@ -93,8 +93,9 @@ int TmModuleGetIDForTM(TmModule *tm); TmEcode TmModuleRegister(char *name, int (*module_func)(ThreadVars *, Packet *, void *)); void TmModuleDebugList(void); void TmModuleRegisterTests(void); +#ifdef PROFILING const char * TmModuleTmmIdToString(TmmId id); - +#endif void TmModuleRunInit(void); void TmModuleRunDeInit(void); diff --git a/src/tm-threads.c b/src/tm-threads.c index aa7c7a03d2..36d9e4ad0f 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -616,27 +616,6 @@ error: return TM_ECODE_FAILED; } -ThreadVars *TmThreadsGetTVContainingSlot(TmSlot *tm_slot) -{ - SCMutexLock(&tv_root_lock); - for (int i = 0; i < TVT_MAX; i++) { - ThreadVars *tv = tv_root[i]; - while (tv) { - TmSlot *slots = tv->tm_slots; - while (slots != NULL) { - if (slots == tm_slot) { - SCMutexUnlock(&tv_root_lock); - return tv; - } - slots = slots->slot_next; - } - tv = tv->next; - } - } - SCMutexUnlock(&tv_root_lock); - return NULL; -} - /** * \brief Appends a new entry to the slots. * @@ -691,34 +670,6 @@ void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data) return; } -/** - * \brief Returns the slot holding a TM with the particular tm_id. - * - * \param tm_id TM id of the TM whose slot has to be returned. - * - * \retval slots Pointer to the slot. - */ -TmSlot *TmSlotGetSlotForTM(int tm_id) -{ - SCMutexLock(&tv_root_lock); - for (int i = 0; i < TVT_MAX; i++) { - ThreadVars *tv = tv_root[i]; - while (tv) { - TmSlot *slots = tv->tm_slots; - while (slots != NULL) { - if (slots->tm_id == tm_id) { - SCMutexUnlock(&tv_root_lock); - return slots; - } - slots = slots->slot_next; - } - tv = tv->next; - } - } - SCMutexUnlock(&tv_root_lock); - return NULL; -} - #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun static int SetCPUAffinitySet(cpu_set_t *cs) { @@ -1484,6 +1435,10 @@ again: return; } +#ifdef DEBUG_VALIDATION +static void TmThreadDumpThreads(void); +#endif + static void TmThreadDebugValidateNoMorePackets(void) { #ifdef DEBUG_VALIDATION @@ -1838,35 +1793,6 @@ void TmThreadContinueThreads() return; } -/** - * \brief Pauses a thread - * - * \param tv Pointer to a TV instance that has to be paused - */ -void TmThreadPause(ThreadVars *tv) -{ - TmThreadsSetFlag(tv, THV_PAUSE); - return; -} - -/** - * \brief Pauses all threads present in tv_root - */ -void TmThreadPauseThreads() -{ - TmThreadsListThreads(); - - SCMutexLock(&tv_root_lock); - for (int i = 0; i < TVT_MAX; i++) { - ThreadVars *tv = tv_root[i]; - while (tv != NULL) { - TmThreadPause(tv); - tv = tv->next; - } - } - SCMutexUnlock(&tv_root_lock); -} - /** * \brief Used to check the thread for certain conditions of failure. */ @@ -2002,31 +1928,6 @@ again: return TM_ECODE_OK; } -/** - * \brief Returns the TV for the calling thread. - * - * \retval tv Pointer to the ThreadVars instance for the calling thread; - * NULL on no match - */ -ThreadVars *TmThreadsGetCallingThread(void) -{ - pthread_t self = pthread_self(); - - SCMutexLock(&tv_root_lock); - for (int i = 0; i < TVT_MAX; i++) { - ThreadVars *tv = tv_root[i]; - while (tv) { - if (pthread_equal(self, tv->t)) { - SCMutexUnlock(&tv_root_lock); - return tv; - } - tv = tv->next; - } - } - SCMutexUnlock(&tv_root_lock); - return NULL; -} - /** * \brief returns a count of all the threads that match the flag */ @@ -2047,6 +1948,7 @@ uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags) return cnt; } +#ifdef DEBUG_VALIDATION static void TmThreadDoDumpSlots(const ThreadVars *tv) { for (TmSlot *s = tv->tm_slots; s != NULL; s = s->slot_next) { @@ -2056,7 +1958,7 @@ static void TmThreadDoDumpSlots(const ThreadVars *tv) } } -void TmThreadDumpThreads(void) +static void TmThreadDumpThreads(void) { SCMutexLock(&tv_root_lock); for (int i = 0; i < TVT_MAX; i++) { @@ -2084,6 +1986,7 @@ void TmThreadDumpThreads(void) SCMutexUnlock(&tv_root_lock); TmThreadsListThreads(); } +#endif typedef struct Thread_ { ThreadVars *tv; /**< threadvars structure */ @@ -2323,40 +2226,6 @@ static inline void ThreadBreakLoop(ThreadVars *tv) } } -/** - * \retval r 1 if packet was accepted, 0 otherwise - * \note if packet was not accepted, it's still the responsibility - * of the caller. - */ -int TmThreadsInjectPacketsById(Packet **packets, const int id) -{ - if (id <= 0 || id > (int)thread_store.threads_size) - return 0; - - int idx = id - 1; - - Thread *t = &thread_store.threads[idx]; - ThreadVars *tv = t->tv; - - if (tv == NULL || tv->stream_pq == NULL) - return 0; - - SCMutexLock(&tv->stream_pq->mutex_q); - while (*packets != NULL) { - PacketEnqueue(tv->stream_pq, *packets); - packets++; - } - SCMutexUnlock(&tv->stream_pq->mutex_q); - - /* wake up listening thread(s) if necessary */ - if (tv->inq != NULL) { - SCCondSignal(&tv->inq->pq->cond_q); - } else if (tv->break_loop) { - ThreadBreakLoop(tv); - } - return 1; -} - /** \brief inject a flow into a threads flow queue */ void TmThreadsInjectFlowById(Flow *f, const int id) diff --git a/src/tm-threads.h b/src/tm-threads.h index 372a9be301..f7a0a57d84 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -78,7 +78,6 @@ extern ThreadVars *tv_root[TVT_MAX]; extern SCMutex tv_root_lock; void TmSlotSetFuncAppend(ThreadVars *, TmModule *, const void *); -TmSlot *TmSlotGetSlotForTM(int); ThreadVars *TmThreadCreate(const char *, const char *, const char *, const char *, const char *, const char *, void *(fn_p)(void *), int); @@ -96,7 +95,6 @@ void TmThreadKillThreads(void); void TmThreadClearThreadsFamily(int family); void TmThreadAppend(ThreadVars *, int); void TmThreadSetGroupName(ThreadVars *tv, const char *name); -void TmThreadDumpThreads(void); TmEcode TmThreadSetCPUAffinity(ThreadVars *, uint16_t); TmEcode TmThreadSetThreadPriority(ThreadVars *, int); @@ -109,11 +107,8 @@ void TmThreadInitMC(ThreadVars *); void TmThreadTestThreadUnPaused(ThreadVars *); void TmThreadContinue(ThreadVars *); void TmThreadContinueThreads(void); -void TmThreadPause(ThreadVars *); -void TmThreadPauseThreads(void); void TmThreadCheckThreadState(void); TmEcode TmThreadWaitOnThreadInit(void); -ThreadVars *TmThreadsGetCallingThread(void); int TmThreadsCheckFlag(ThreadVars *, uint32_t); void TmThreadsSetFlag(ThreadVars *, uint32_t); @@ -122,7 +117,6 @@ void TmThreadWaitForFlag(ThreadVars *, uint32_t); TmEcode TmThreadsSlotVarRun (ThreadVars *tv, Packet *p, TmSlot *slot); -ThreadVars *TmThreadsGetTVContainingSlot(TmSlot *); void TmThreadDisablePacketThreads(void); void TmThreadDisableReceiveThreads(void); @@ -256,7 +250,6 @@ static inline void TmThreadsCaptureHandleTimeout(ThreadVars *tv, Packet *p) void TmThreadsListThreads(void); int TmThreadsRegisterThread(ThreadVars *tv, const int type); void TmThreadsUnregisterThread(const int id); -int TmThreadsInjectPacketsById(Packet **, int id); void TmThreadsInjectFlowById(Flow *f, const int id); void TmThreadsInitThreadsTimestamp(const struct timeval *ts);