From 8d06d7bccc431fda671bacca482fd98264b660fb Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 23 Oct 2015 18:09:24 +0200 Subject: [PATCH] threads: add func to count running threads of types --- src/tm-threads.c | 23 +++++++++++++++++++++++ src/tm-threads.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/tm-threads.c b/src/tm-threads.c index b47d4b050d..2b26404fba 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -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; diff --git a/src/tm-threads.h b/src/tm-threads.h index 9b9fd620df..397fbd2e86 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -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. */