Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
Public Member Functions | Private Attributes | List of all members
CThreadSafeQueue< data > Class Template Reference

Thread safe queue. More...

#include <ThreadSafeQueue.h>

Public Member Functions

void push (const data &element)
 Insert at tail. More...
 
bool pop (data &element)
 Delete from head and return. More...
 
size_t size ()
 Get queue size. More...
 

Private Attributes

std::queue< data > m_stdQueue
 Queue contents.
 
std::mutex m_mutex
 Mutex for thread safety.
 

Detailed Description

template<class data>
class CThreadSafeQueue< data >

A safe queue data structure for inter-thread communication. A mutex is used to prevent multiple threads attempting to enqueue or dequeue at the same time.

Definition at line 37 of file ThreadSafeQueue.h.

Member Function Documentation

◆ pop()

template<class data>
bool CThreadSafeQueue< data >::pop ( data &  element)

Delete and return the element at the head of the queue.

Parameters
element[out] The element at the head of the queue.
Returns
true If the queue was non-empty.

Definition at line 42 of file ThreadSafeQueue.cpp.

◆ push()

template<class data>
void CThreadSafeQueue< data >::push ( const data &  element)

Insert an element at the end of the queue.

Parameters
elementAn element.

Definition at line 32 of file ThreadSafeQueue.cpp.

◆ size()

template<class data >
size_t CThreadSafeQueue< data >::size ( )

Get the number of things in the queue.

Returns
the number of things in the queue.

Definition at line 59 of file ThreadSafeQueue.cpp.