group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
EventQueue Class Reference

Thread-safe FIFO queue of gameplay events awaiting processing each tick. More...

#include <EventQueue.hpp>

Public Member Functions

bool isEmpty ()
 Check whether the queue contains no events.
void enqueue (Event event)
 Push an event onto the back of the queue.
Event dequeue ()
 Remove and return the front event.
int size ()
 Return the number of pending events.
void drainAll (std::vector< Event > &out)
 PR-2b (server-perf): drain every queued event into out in FIFO order.

Private Attributes

std::queue< Eventevents
 Underlying FIFO storage.
std::mutex queueMutex
 Guards events for cross-thread access.

Detailed Description

Thread-safe FIFO queue of gameplay events awaiting processing each tick.

PR-2c (server-perf): the queue holds its own mutex now. Pre-PR-2c the Server's stateMutex_ doubled as the eventQueue lock — every enqueue (called inside readClients, on the network thread) and every drainAll (called from tick(), on the game thread) acquired the same mutex that protects the clients map. Result: the game thread's drainEvents blocked on the network thread's readClients per-cycle work, contributing ~12 ms p99 to tick time at 100 bots. With this mutex, the two paths only compete on the queue itself — a much shorter critical section.

Member Function Documentation

◆ dequeue()

Event EventQueue::dequeue ( )

Remove and return the front event.

Returns
The oldest pending event.

◆ drainAll()

void EventQueue::drainAll ( std::vector< Event > & out)

PR-2b (server-perf): drain every queued event into out in FIFO order.

Single-pass; the queue is empty afterwards. Used by the game thread to avoid per-event lock acquisition against the network thread's enqueue path.

◆ enqueue()

void EventQueue::enqueue ( Event event)

Push an event onto the back of the queue.

Parameters
eventThe event to enqueue.

◆ isEmpty()

bool EventQueue::isEmpty ( )

Check whether the queue contains no events.

Returns
True if the queue is empty.

◆ size()

int EventQueue::size ( )

Return the number of pending events.

Returns
Queue size.

Member Data Documentation

◆ events

std::queue<Event> EventQueue::events
private

Underlying FIFO storage.

◆ queueMutex

std::mutex EventQueue::queueMutex
mutableprivate

Guards events for cross-thread access.


The documentation for this class was generated from the following files: