Thread++
Client-Server Multithreading with C++
Public Member Functions | Private Attributes | List of all members
CThreadSafeQueue< CTaskClass > Class Template Reference

Thread safe queue. More...

#include <ThreadSafeQueue.h>

Public Member Functions

 CThreadSafeQueue ()
 Constructor. More...
 
 ~CThreadSafeQueue ()
 Destructor. More...
 
void Insert (const CTaskClass &element)
 Insert task at tail. More...
 
bool Delete (CTaskClass &element)
 Delete task from head. More...
 
void Flush ()
 Flush out and discard all tasks in queue. More...
 

Private Attributes

std::mutex m_stdMutex
 Mutex for thread safety.
 
std::queue< CTaskClass > m_stdQueue
 The task descriptor queue.
 

Detailed Description

template<class CTaskClass>
class CThreadSafeQueue< CTaskClass >

A thread-safe queue of task descriptors for communicating between the threads and the thread manager. It uses an std::mutex for safety.

Template Parameters
CTaskClassTask descriptor.

Constructor & Destructor Documentation

◆ CThreadSafeQueue()

template<class CTaskClass >
CThreadSafeQueue< CTaskClass >::CThreadSafeQueue

Default constructor.

Template Parameters
CTaskClassTask descriptor.

◆ ~CThreadSafeQueue()

template<class CTaskClass >
CThreadSafeQueue< CTaskClass >::~CThreadSafeQueue

Default destructor.

Template Parameters
CTaskClassTask descriptor.

Member Function Documentation

◆ Delete()

template<class CTaskClass >
bool CThreadSafeQueue< CTaskClass >::Delete ( CTaskClass &  element)

Delete and return a task descriptor from the queue. A mutex is used to ensure thread safety.

Template Parameters
CTaskClassTask descriptor.
Parameters
element[OUT] The element deleted from the queue.
Returns
true if the delete was successful, ie. the queue was not empty.

◆ Flush()

template<class CTaskClass >
void CThreadSafeQueue< CTaskClass >::Flush

Flush all task descriptors out of the queue without processing them. A mutex is used to ensure thread safety.

Template Parameters
CTaskClassTask descriptor.

◆ Insert()

template<class CTaskClass >
void CThreadSafeQueue< CTaskClass >::Insert ( const CTaskClass &  element)

Insert a task descriptor into the queue. A mutex is used to ensure thread safety.

Template Parameters
CTaskClassTask descriptor.
Parameters
elementThe element to be inserted into the queue.