]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threading: remove handler names to shink struct
authorVictor Julien <victor@inliniac.net>
Mon, 11 Nov 2019 19:49:24 +0000 (20:49 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 7 Feb 2020 14:43:10 +0000 (15:43 +0100)
Shrink ThreadVars by removing the queue handler names that are only
used at shutdown. Since this is not performance critical, we can use
the id's to look up the queue handler.

src/threadvars.h
src/tm-threads.c

index 3c468fbb480c30a76db79c189a40317adbb8ec79..0caa459cc0f6b88ac51b182f5c6fb5f01c7e163f 100644 (file)
@@ -67,6 +67,9 @@ typedef struct ThreadVars_ {
 
     uint8_t cap_flags; /**< Flags to indicate the capabilities of all the
                             TmModules resgitered under this thread */
+    uint8_t inq_id;
+    uint8_t outq_id;
+
     /** local id */
     int id;
 
@@ -74,11 +77,9 @@ typedef struct ThreadVars_ {
     Tmq *inq;
     Tmq *outq;
     void *outctx;
-    const char *outqh_name;
 
     /** queue handlers */
     struct Packet_ * (*tmqh_in)(struct ThreadVars_ *);
-    void (*InShutdownHandler)(struct ThreadVars_ *);
     void (*tmqh_out)(struct ThreadVars_ *, struct Packet_ *);
 
     /** function pointer to the function that runs the packet pipeline for
index ff6e8b56a270750f501faf644a4f93294c841fbf..878934e1c77204690ba419b894ac7d48e0c9e110 100644 (file)
@@ -1109,12 +1109,16 @@ ThreadVars *TmThreadCreate(const char *name, const char *inq_name, const char *i
     if (inqh_name != NULL) {
         SCLogDebug("inqh_name \"%s\"", inqh_name);
 
+        int id = TmqhNameToID(inqh_name);
+        if (id <= 0) {
+            goto error;
+        }
         tmqh = TmqhGetQueueHandlerByName(inqh_name);
         if (tmqh == NULL)
             goto error;
 
         tv->tmqh_in = tmqh->InHandler;
-        tv->InShutdownHandler = tmqh->InShutdownHandler;
+        tv->inq_id = (uint8_t)id;
         SCLogDebug("tv->tmqh_in %p", tv->tmqh_in);
     }
 
@@ -1122,12 +1126,17 @@ ThreadVars *TmThreadCreate(const char *name, const char *inq_name, const char *i
     if (outqh_name != NULL) {
         SCLogDebug("outqh_name \"%s\"", outqh_name);
 
+        int id = TmqhNameToID(outqh_name);
+        if (id <= 0) {
+            goto error;
+        }
+
         tmqh = TmqhGetQueueHandlerByName(outqh_name);
         if (tmqh == NULL)
             goto error;
 
         tv->tmqh_out = tmqh->OutHandler;
-        tv->outqh_name = tmqh->name;
+        tv->outq_id = (uint8_t)id;
 
         if (outq_name != NULL && strcmp(outq_name, "packetpool") != 0) {
             SCLogDebug("outq_name \"%s\"", outq_name);
@@ -1423,8 +1432,11 @@ static int TmThreadKillThread(ThreadVars *tv)
 
     /* to be sure, signal more */
     if (!(TmThreadsCheckFlag(tv, THV_CLOSED))) {
-        if (tv->InShutdownHandler != NULL) {
-            tv->InShutdownHandler(tv);
+        if (tv->inq_id != TMQH_NOT_SET) {
+            Tmqh *qh = TmqhGetQueueHandlerByID(tv->inq_id);
+            if (qh != NULL && qh->InShutdownHandler != NULL) {
+                qh->InShutdownHandler(tv);
+            }
         }
         if (tv->inq != NULL) {
             for (int i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
@@ -1440,13 +1452,12 @@ static int TmThreadKillThread(ThreadVars *tv)
     }
 
     if (tv->outctx != NULL) {
-        Tmqh *tmqh = TmqhGetQueueHandlerByName(tv->outqh_name);
-        if (tmqh == NULL)
-            BUG_ON(1);
-
-        if (tmqh->OutHandlerCtxFree != NULL) {
-            tmqh->OutHandlerCtxFree(tv->outctx);
-            tv->outctx = NULL;
+        if (tv->outq_id != TMQH_NOT_SET) {
+            Tmqh *qh = TmqhGetQueueHandlerByID(tv->outq_id);
+            if (qh != NULL && qh->OutHandlerCtxFree != NULL) {
+                qh->OutHandlerCtxFree(tv->outctx);
+                tv->outctx = NULL;
+            }
         }
     }