]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads/flow: assist branch prediction
authorVictor Julien <vjulien@oisf.net>
Mon, 11 Sep 2023 07:21:47 +0000 (07:21 +0000)
committerVictor Julien <victor@inliniac.net>
Tue, 25 Feb 2025 14:49:32 +0000 (15:49 +0100)
src/tm-threads.c

index 516bf997b7744a07ab5d805e36cb8f4b039c5871..dca77281ce665c9dc08a7810dbc80d4a522584a9 100644 (file)
@@ -2345,23 +2345,23 @@ uint16_t TmThreadsGetWorkerThreadMax(void)
  */
 void TmThreadsInjectFlowById(Flow *f, const int id)
 {
-    BUG_ON(id <= 0 || id > (int)thread_store.threads_size);
-
-    int idx = id - 1;
-
-    Thread *t = &thread_store.threads[idx];
-    ThreadVars *tv = t->tv;
-
-    BUG_ON(tv == NULL || tv->flow_queue == NULL);
-
-    FlowEnqueue(tv->flow_queue, f);
-
-    /* wake up listening thread(s) if necessary */
-    if (tv->inq != NULL) {
-        SCMutexLock(&tv->inq->pq->mutex_q);
-        SCCondSignal(&tv->inq->pq->cond_q);
-        SCMutexUnlock(&tv->inq->pq->mutex_q);
-    } else if (tv->break_loop) {
-        TmThreadsCaptureBreakLoop(tv);
+    if (id > 0 && id <= (int)thread_store.threads_size) {
+        int idx = id - 1;
+        Thread *t = &thread_store.threads[idx];
+        ThreadVars *tv = t->tv;
+        if (tv != NULL && tv->flow_queue != NULL) {
+            FlowEnqueue(tv->flow_queue, f);
+
+            /* wake up listening thread(s) if necessary */
+            if (tv->inq != NULL) {
+                SCMutexLock(&tv->inq->pq->mutex_q);
+                SCCondSignal(&tv->inq->pq->cond_q);
+                SCMutexUnlock(&tv->inq->pq->mutex_q);
+            } else if (tv->break_loop) {
+                TmThreadsCaptureBreakLoop(tv);
+            }
+            return;
+        }
     }
+    BUG_ON(1);
 }