OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
Utils::ThreadSafeQueue< T > Class Template Reference

#include <ThreadSafeQueue.h>

Inheritance diagram for Utils::ThreadSafeQueue< T >:
[legend]

Public Types

enum class  wait_result { timed_out , interrupted , notified }
 
typedef std::function< void(const std::string &)> internalLogHandlerProc
 

Public Member Functions

 ThreadSafeQueue ()
 
void push (T &&item)
 
T & front (bool wait)
 
void pop ()
 
void interrupt ()
 
wait_result wait ()
 
wait_result wait (std::chrono::milliseconds wait_ms)
 
bool empty ()
 
void registerInternalLogHandler (internalLogHandlerProc internalLogHandler)
 

Detailed Description

template<typename T>
class Utils::ThreadSafeQueue< T >

std::_queue wrapped in thread-safety mechanisms

Template Parameters
Ttype of _queue's items

Definition at line 24 of file ThreadSafeQueue.h.

Member Typedef Documentation

◆ internalLogHandlerProc

template<typename T >
typedef std::function<void(const std::string&)> Utils::ThreadSafeQueue< T >::internalLogHandlerProc

Definition at line 27 of file ThreadSafeQueue.h.

Member Enumeration Documentation

◆ wait_result

template<typename T >
enum class Utils::ThreadSafeQueue::wait_result
strong
Enumerator
timed_out 
interrupted 
notified 

Definition at line 29 of file ThreadSafeQueue.h.

Constructor & Destructor Documentation

◆ ThreadSafeQueue()

template<typename T >
Utils::ThreadSafeQueue< T >::ThreadSafeQueue ( )
inline

Definition at line 36 of file ThreadSafeQueue.h.

Member Function Documentation

◆ empty()

template<typename T >
bool Utils::ThreadSafeQueue< T >::empty ( )

Check if _queue is empty

Returns
true if _queue is empty, false otherwise

Definition at line 232 of file ThreadSafeQueue.h.

◆ front()

template<typename T >
T & Utils::ThreadSafeQueue< T >::front ( bool  wait)

Get a reference to the head of the _queue in a type-safe manner

Parameters
waitwhether to wait for the _queue to become not empty and notified
Returns
reference to the item

Definition at line 130 of file ThreadSafeQueue.h.

Here is the caller graph for this function:

◆ interrupt()

template<typename T >
void Utils::ThreadSafeQueue< T >::interrupt ( )

Set the interrupt and notify any wait()'s on the _queue without push();ing an item

Definition at line 152 of file ThreadSafeQueue.h.

◆ pop()

template<typename T >
void Utils::ThreadSafeQueue< T >::pop ( )

Remove last item off the _queue

Definition at line 145 of file ThreadSafeQueue.h.

◆ push()

template<typename T >
void Utils::ThreadSafeQueue< T >::push ( T &&  item)

Push an object onto the _queue in a thread-safe manner

Parameters
itemitem to push onto _queue

Definition at line 102 of file ThreadSafeQueue.h.

◆ registerInternalLogHandler()

template<typename T >
void Utils::ThreadSafeQueue< T >::registerInternalLogHandler ( ThreadSafeQueue< T >::internalLogHandlerProc  internalLogHandler)

Sets a function that is used to handle internal-level log messages. Invoked when logInternal() is called.

Parameters
internal_log_handlerfunction to invoke when internal messages need to be logged

Definition at line 248 of file ThreadSafeQueue.h.

Here is the caller graph for this function:

◆ wait() [1/2]

template<typename T >
ThreadSafeQueue< T >::wait_result Utils::ThreadSafeQueue< T >::wait ( )

Wait indefinitely for the _queue to be notified by either push() or interrupt()

Returns
wait_result specifying result of waiting, one of: { notified, interrupted }

Definition at line 165 of file ThreadSafeQueue.h.

◆ wait() [2/2]

template<typename T >
ThreadSafeQueue< T >::wait_result Utils::ThreadSafeQueue< T >::wait ( std::chrono::milliseconds  wait_ms)

Waits given duration for the _queue to be notified by either push() or interrupt(), or to time out

Parameters
wait_msstd::chrono::duration specifying duration, in ms, to wait before timing out
Returns
wait_result specifying result of waiting, one of: { notified, interrupted, timed_out }

Definition at line 196 of file ThreadSafeQueue.h.


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