]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packet-queue: introduce a non-locked version
authorVictor Julien <victor@inliniac.net>
Tue, 12 Nov 2019 13:54:55 +0000 (14:54 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 7 Feb 2020 14:43:10 +0000 (15:43 +0100)
Works exactly like PacketQueue, just does not contain a mutex
and cond var, leading to much reduced memory size.

src/decode.h
src/packet-queue.c
src/packet-queue.h

index c31b83792a11b3db30836dba9374d405c5c2ede1..a15c193c862f8f1fdf6459cdb7926b7ad6952e8b 100644 (file)
@@ -618,6 +618,26 @@ extern int g_default_mtu;
 uint32_t default_packet_size;
 #define SIZE_OF_PACKET (default_packet_size + sizeof(Packet))
 
+/** \brief simple fifo queue for packets
+ *
+ *  \note PacketQueueNoLock and PacketQueue need to keep identical
+ *        layouts except for the mutex_q and cond_q fields.
+ */
+typedef struct PacketQueueNoLock_ {
+    Packet *top;
+    Packet *bot;
+    uint32_t len;
+#ifdef DBG_PERF
+    uint32_t dbg_maxlen;
+#endif /* DBG_PERF */
+} PacketQueueNoLock;
+
+/** \brief simple fifo queue for packets with mutex and cond
+ *  Calling the mutex or triggering the cond is responsibility of the caller
+ *
+ *  \note PacketQueueNoLock and PacketQueue need to keep identical
+ *        layouts except for the mutex_q and cond_q fields.
+ */
 typedef struct PacketQueue_ {
     Packet *top;
     Packet *bot;
index 9f5bf43090040cc6c5b883b5fd0689b4995e1d76..ef4e434cad86b6d0a74bc5d90005f7dd7bb971a7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2019 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -136,7 +136,7 @@ void PacketQueueValidate(PacketQueue *q)
 }
 #endif /* DEBUG */
 
-void PacketEnqueue (PacketQueue *q, Packet *p)
+static inline void PacketEnqueueDo(PacketQueue *q, Packet *p)
 {
     //PacketQueueValidateDebug(q);
 
@@ -164,25 +164,28 @@ void PacketEnqueue (PacketQueue *q, Packet *p)
     //PacketQueueValidateDebug(q);
 }
 
-Packet *PacketDequeue (PacketQueue *q)
+void PacketEnqueueNoLock(PacketQueueNoLock *qnl, Packet *p)
+{
+    PacketQueue *q = (PacketQueue *)qnl;
+    PacketEnqueueDo(q, p);
+}
+
+void PacketEnqueue (PacketQueue *q, Packet *p)
 {
-    Packet *p = NULL;
+    PacketEnqueueDo(q, p);
+}
 
+static inline Packet *PacketDequeueDo (PacketQueue *q)
+{
     //PacketQueueValidateDebug(q);
     /* if the queue is empty there are no packets left. */
     if (q->len == 0) {
         return NULL;
     }
-
     q->len--;
 
     /* pull the bottom packet from the queue */
-    p = q->bot;
-
-    /* Weird issue: sometimes it looks that two thread arrive
-     * here at the same time so the bot ptr is NULL (only on OS X?)
-     */
-    BUG_ON (p == NULL);
+    Packet *p = q->bot;
 
     /* more packets in queue */
     if (q->bot->prev != NULL) {
@@ -200,3 +203,13 @@ Packet *PacketDequeue (PacketQueue *q)
     return p;
 }
 
+Packet *PacketDequeueNoLock (PacketQueueNoLock *qnl)
+{
+    PacketQueue *q = (PacketQueue *)qnl;
+    return PacketDequeueDo(q);
+}
+
+Packet *PacketDequeue (PacketQueue *q)
+{
+    return PacketDequeueDo(q);
+}
index b93a942b6a9d4d2ec862427ee23d1aca742c210a..77a0d87ef24e097721d74e244e48b893dff89d67 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2019 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
 #include "threads.h"
 #include "decode.h"
 
+void PacketEnqueueNoLock(PacketQueueNoLock *qnl, Packet *p);
 void PacketEnqueue (PacketQueue *, Packet *);
+
+Packet *PacketDequeueNoLock (PacketQueueNoLock *qnl);
 Packet *PacketDequeue (PacketQueue *);
 
 #endif /* __PACKET_QUEUE_H__ */