ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
packet_queue_t Struct Reference

Thread-safe packet queue for producer-consumer communication. More...

#include <include/ascii-chat/network/packet/queue.h>

Data Fields

atomic_ptr_t head
 Front of queue (dequeue from here) - atomic for lock-free access.
 
atomic_ptr_t tail
 Back of queue (enqueue here) - atomic for lock-free access.
 
atomic_t count
 Number of packets currently in queue - atomic for lock-free access.
 
size_t max_size
 Maximum queue size (0 = unlimited)
 
atomic_t bytes_queued
 Total bytes of data queued (for monitoring) - atomic for lock-free access.
 
node_pool_t * node_pool
 Optional memory pool for nodes (NULL = use malloc/free)
 
buffer_pool_t * buffer_pool
 Optional memory pool for data buffers (NULL = use malloc/free)
 
atomic_t packets_enqueued
 Total packets enqueued (statistics) - atomic for lock-free access.
 
atomic_t packets_dequeued
 Total packets dequeued (statistics) - atomic for lock-free access.
 
atomic_t packets_dropped
 Total packets dropped due to queue full (statistics) - atomic for lock-free access.
 
atomic_t shutdown
 Shutdown flag (true = dequeue returns NULL) - atomic for lock-free access.
 

Detailed Description

Thread-safe packet queue for producer-consumer communication.

Implements a FIFO queue with blocking operations for efficient thread coordination. Producers (audio mixer, video render) enqueue packets asynchronously, while consumers (per-client send threads) dequeue packets for transmission.

QUEUE OPERATIONS:

  • Enqueue: Add packet to tail of queue (non-blocking, drops oldest if full)
  • Dequeue: Remove packet from head of queue (non-blocking, returns NULL if empty)
  • Try-dequeue: Non-blocking dequeue (returns NULL if empty) - same as dequeue

MEMORY POOLS:

  • node_pool: Optional pool for queue nodes (reduces malloc overhead)
  • buffer_pool: Optional pool for packet data (enables zero-allocation)

SYNCHRONIZATION:

  • Atomic head/tail pointers: Lock-free queue state management
  • Atomic count: Fast size checks without locking
  • Atomic statistics: Lock-free performance monitoring
  • Atomic shutdown flag: Graceful shutdown without blocking
Note
When max_size is 0, queue is unlimited (may grow without bound). When max_size > 0, full queues drop oldest packets automatically.
Statistics track enqueue/dequeue/drop counts for performance monitoring.
Warning
Queue destruction does NOT free packets still in queue. Clear queue first or ensure all packets are dequeued before destruction.

Definition at line 211 of file queue.h.


The documentation for this struct was generated from the following file: