Packet *PacketPoolGetPacket(void)
{
PktPool *pool = GetThreadPacketPool();
-
+#ifdef DEBUG_VALIDATION
+ BUG_ON(pool->initialized == 0);
+ BUG_ON(pool->destroyed == 1);
+#endif /* DEBUG_VALIDATION */
if (pool->head) {
/* Stack is not empty. */
Packet *p = pool->head;
PacketFree(p);
return;
}
+#ifdef DEBUG_VALIDATION
+ BUG_ON(pool->initialized == 0);
+ BUG_ON(pool->destroyed == 1);
+ BUG_ON(my_pool->initialized == 0);
+ BUG_ON(my_pool->destroyed == 1);
+#endif /* DEBUG_VALIDATION */
if (pool == my_pool) {
/* Push back onto this thread's own stack, so no locking. */
PktPool *my_pool = GetThreadPacketPool();
+#ifdef DEBUG_VALIDATION
+ BUG_ON(my_pool->initialized);
+ my_pool->initialized = 1;
+ my_pool->destroyed = 0;
+#endif /* DEBUG_VALIDATION */
+
SCMutexInit(&my_pool->return_stack.mutex, NULL);
SCCondInit(&my_pool->return_stack.cond, NULL);
SC_ATOMIC_INIT(my_pool->return_stack.sync_now);
PktPool *my_pool = GetThreadPacketPool();
+#ifdef DEBUG_VALIDATION
+ BUG_ON(my_pool->initialized);
+ my_pool->initialized = 1;
+ my_pool->destroyed = 0;
+#endif /* DEBUG_VALIDATION */
+
SCMutexInit(&my_pool->return_stack.mutex, NULL);
SCCondInit(&my_pool->return_stack.cond, NULL);
SC_ATOMIC_INIT(my_pool->return_stack.sync_now);
}
SCLogInfo("preallocated %"PRIiMAX" packets. Total memory %"PRIuMAX"",
max_pending_packets, (uintmax_t)(max_pending_packets*SIZE_OF_PACKET));
+
}
void PacketPoolDestroy(void)
{
Packet *p = NULL;
PktPool *my_pool = GetThreadPacketPool();
+
+#ifdef DEBUG_VALIDATION
+ BUG_ON(my_pool->destroyed);
+#endif /* DEBUG_VALIDATION */
+
if (my_pool && my_pool->pending_pool != NULL) {
p = my_pool->pending_head;
while (p) {
p = next_p;
my_pool->pending_count--;
}
+#ifdef DEBUG_VALIDATION
BUG_ON(my_pool->pending_count);
+#endif /* DEBUG_VALIDATION */
my_pool->pending_pool = NULL;
my_pool->pending_head = NULL;
my_pool->pending_tail = NULL;
}
SC_ATOMIC_DESTROY(my_pool->return_stack.sync_now);
+
+#ifdef DEBUG_VALIDATION
+ my_pool->initialized = 0;
+ my_pool->destroyed = 1;
+#endif /* DEBUG_VALIDATION */
}
Packet *TmqhInputPacketpool(ThreadVars *tv)
} __attribute__((aligned(CLS))) PktPoolLockedStack;
typedef struct PktPool_ {
- /* link listed of free packets local to this thread.
+ /* link listed of free packets local to this thread.
* No mutex is needed.
*/
Packet *head;
Packet *pending_head;
Packet *pending_tail;
uint32_t pending_count;
-
- /* All members above this point are accessed locally by only one thread, so
+
+#ifdef DEBUG_VALIDATION
+ int initialized;
+ int destroyed;
+#endif /* DEBUG_VALIDATION */
+
+ /* All members above this point are accessed locally by only one thread, so
* these should live on their own cache line.
*/
* to this thread.
*/
PktPoolLockedStack return_stack;
-
} PktPool;
Packet *TmqhInputPacketpool(ThreadVars *);