|
group2 0.1.0
CSE 125 Group 2
|
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< Event > | events |
| Underlying FIFO storage. | |
| std::mutex | queueMutex |
| Guards events for cross-thread access. | |
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.
| Event EventQueue::dequeue | ( | ) |
Remove and return the front event.
| 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.
| void EventQueue::enqueue | ( | Event | event | ) |
Push an event onto the back of the queue.
| event | The event to enqueue. |
| bool EventQueue::isEmpty | ( | ) |
Check whether the queue contains no events.
| int EventQueue::size | ( | ) |
Return the number of pending events.
|
private |
Underlying FIFO storage.
|
mutableprivate |
Guards events for cross-thread access.