|
R-Type
Distributed multiplayer game engine in C++
|
Thread-safe queue for inter-thread communication. More...
#include <ThreadSafeQueue.hpp>

Public Member Functions | |
| ThreadSafeQueue ()=default | |
| ~ThreadSafeQueue ()=default | |
| ThreadSafeQueue (const ThreadSafeQueue &)=delete | |
| ThreadSafeQueue & | operator= (const ThreadSafeQueue &)=delete |
| void | push (T item) |
| Push an item to the queue. | |
| std::optional< T > | tryPop () |
| Try to pop an item without blocking. | |
| T | pop () |
| Pop an item, blocking until one is available. | |
| bool | empty () const |
| Check if queue is empty. | |
| size_t | size () const |
| Get queue size. | |
| void | clear () |
| Clear all items from queue. | |
Private Attributes | |
| std::mutex | _mutex |
| std::condition_variable | _cv |
| std::queue< T > | _queue |
Thread-safe queue for inter-thread communication.
This queue allows one thread to push items and another to pop them without race conditions. Uses mutex and condition variable for synchronization.
| T | Type of elements stored in the queue |
Definition at line 25 of file ThreadSafeQueue.hpp.
|
default |
|
default |
|
delete |
|
inline |
Clear all items from queue.
Thread-safe.
Definition at line 103 of file ThreadSafeQueue.hpp.
References ThreadSafeQueue< T >::_mutex, and ThreadSafeQueue< T >::_queue.
|
inline |
Check if queue is empty.
Thread-safe.
Definition at line 82 of file ThreadSafeQueue.hpp.
References ThreadSafeQueue< T >::_mutex, and ThreadSafeQueue< T >::_queue.
|
delete |
|
inline |
Pop an item, blocking until one is available.
Thread-safe. Blocks until an item is available.
Definition at line 68 of file ThreadSafeQueue.hpp.
References ThreadSafeQueue< T >::_cv, ThreadSafeQueue< T >::_mutex, and ThreadSafeQueue< T >::_queue.
Referenced by server::ThreadPool::_workerLoop().
|
inline |
Push an item to the queue.
| item | Item to push |
Thread-safe. Notifies waiting threads.
Definition at line 40 of file ThreadSafeQueue.hpp.
References ThreadSafeQueue< T >::_cv, ThreadSafeQueue< T >::_mutex, and ThreadSafeQueue< T >::_queue.
Referenced by server::ThreadPool::enqueue(), Replicator::networkThreadLoop(), ServerNetworkManager::networkThreadLoop(), and server::ThreadPool::stop().
|
inline |
Get queue size.
Thread-safe.
Definition at line 93 of file ThreadSafeQueue.hpp.
References ThreadSafeQueue< T >::_mutex, and ThreadSafeQueue< T >::_queue.
|
inline |
Try to pop an item without blocking.
Thread-safe. Returns immediately.
Definition at line 52 of file ThreadSafeQueue.hpp.
References ThreadSafeQueue< T >::_mutex, and ThreadSafeQueue< T >::_queue.
Referenced by Replicator::processMessages(), and ServerNetworkManager::processMessages().
|
private |
Definition at line 111 of file ThreadSafeQueue.hpp.
Referenced by ThreadSafeQueue< T >::pop(), and ThreadSafeQueue< T >::push().
|
mutableprivate |
Definition at line 110 of file ThreadSafeQueue.hpp.
Referenced by ThreadSafeQueue< T >::clear(), ThreadSafeQueue< T >::empty(), ThreadSafeQueue< T >::pop(), ThreadSafeQueue< T >::push(), ThreadSafeQueue< T >::size(), and ThreadSafeQueue< T >::tryPop().
|
private |
Definition at line 112 of file ThreadSafeQueue.hpp.
Referenced by ThreadSafeQueue< T >::clear(), ThreadSafeQueue< T >::empty(), ThreadSafeQueue< T >::pop(), ThreadSafeQueue< T >::push(), ThreadSafeQueue< T >::size(), and ThreadSafeQueue< T >::tryPop().