]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: remove usused code; wrap in guards
authorVictor Julien <vjulien@oisf.net>
Wed, 27 Apr 2022 15:21:25 +0000 (17:21 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 9 May 2022 14:06:40 +0000 (16:06 +0200)
src/tm-modules.c
src/tm-modules.h
src/tm-threads.c
src/tm-threads.h

index 354770057ef8bca38835395402480679430e73d1..bbf11b3156d240bf18b0afd70a7e11de60cc47ce 100644 (file)
@@ -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 "<unknown>";
 }
+#endif
index 7df5b91be39494c5efa024d0aa171a1ad9d37a04..7b697f2ec49af5561cea3e8b95263b1565c6ce0f 100644 (file)
@@ -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);
 
index aa7c7a03d28c783a7d9e92c6ae37e2a009027600..36d9e4ad0fadafff9c75efaf3f6088940b3a8c8a 100644 (file)
@@ -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)
index 372a9be3019afcf4274ece01d920b0e3bef10eb3..f7a0a57d8470a8f2b2a09439704b971d1c189240 100644 (file)
@@ -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);