]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: add func to count running threads of types
authorVictor Julien <victor@inliniac.net>
Fri, 23 Oct 2015 16:09:24 +0000 (18:09 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 26 Oct 2015 08:11:56 +0000 (09:11 +0100)
src/tm-threads.c
src/tm-threads.h

index b47d4b050dd90d1b8febd4085852a7416e68f228..2b26404fbaaf5730b0928f09a1f1edc0d70518e5 100644 (file)
@@ -2034,6 +2034,29 @@ ThreadVars *TmThreadsGetCallingThread(void)
     return NULL;
 }
 
+/**
+ * \brief returns a count of all the threads that match the flag
+ */
+uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags)
+{
+    ThreadVars *tv = NULL;
+    int i = 0;
+    uint32_t cnt = 0;
+
+    SCMutexLock(&tv_root_lock);
+    for (i = 0; i < TVT_MAX; i++) {
+        tv = tv_root[i];
+        while (tv != NULL) {
+            if ((tv->tmm_flags & flags) == flags)
+                cnt++;
+
+            tv = tv->next;
+        }
+    }
+    SCMutexUnlock(&tv_root_lock);
+    return cnt;
+}
+
 typedef struct Thread_ {
     ThreadVars *tv;     /**< threadvars structure */
     const char *name;
index 9b9fd620dfd4fcff8004c4dfefa0525e09078cec..397fbd2e86b0f0383992bab1bdfd4182ae02f8a7 100644 (file)
@@ -132,6 +132,8 @@ void TmThreadDisablePacketThreads(void);
 void TmThreadDisableReceiveThreads(void);
 TmSlot *TmThreadGetFirstTmSlotForPartialPattern(const char *);
 
+uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags);
+
 /**
  *  \brief Process the rest of the functions (if any) and queue.
  */