packet-queue: introduce a non-locked version

Works exactly like PacketQueue, just does not contain a mutex
and cond var, leading to much reduced memory size.
pull/4531/head
Victor Julien 7 years ago
parent 9ed260c489
commit b8c2b66d33

@ -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;

@ -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);
}

@ -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
@ -27,7 +27,10 @@
#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__ */

Loading…
Cancel
Save