ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
packet_queue_t Struct Reference

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

#include <lib/network/packet_queue.h>

Public Member Functions

 _Atomic (packet_node_t *) head
 Front of queue (dequeue from here) - atomic for lock-free access.
 
 _Atomic (packet_node_t *) tail
 Back of queue (enqueue here) - atomic for lock-free access.
 

Data Fields

_Atomic size_t count
 Number of packets currently in queue - atomic for lock-free access.
 
size_t max_size
 Maximum queue size (0 = unlimited)
 
_Atomic size_t bytes_queued
 Total bytes of data queued (for monitoring) - atomic for lock-free access.
 
node_pool_tnode_pool
 Optional memory pool for nodes (NULL = use malloc/free)
 
buffer_pool_tbuffer_pool
 Optional memory pool for data buffers (NULL = use malloc/free)
 
_Atomic uint64_t packets_enqueued
 Total packets enqueued (statistics) - atomic for lock-free access.
 
_Atomic uint64_t packets_dequeued
 Total packets dequeued (statistics) - atomic for lock-free access.
 
_Atomic uint64_t packets_dropped
 Total packets dropped due to queue full (statistics) - atomic for lock-free access.
 
_Atomic bool 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 213 of file packet_queue.h.

Member Function Documentation

◆ _Atomic()

packet_queue_t::_Atomic ( packet_node_t )

Back of queue (enqueue here) - atomic for lock-free access.


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