OKVIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Friends | List of all members
okvis::threadsafe::ThreadSafeQueue< QueueType > Class Template Reference

Class that implements a threadsafe FIFO queue. More...

#include <ThreadsafeQueue.hpp>

Public Member Functions

virtual void NotifyAll () const final
 Notify all waiting threads. Only used in destructor and when shutting down. More...
 
 ThreadSafeQueue ()
 Constructor. More...
 
virtual ~ThreadSafeQueue ()
 Destructor. More...
 
virtual void Shutdown () final
 Tell the queue shut down. This will notify all threads to wake up. More...
 
virtual void Resume () final
 Tell the queue to resume after a shutdown request. More...
 
void Push (const QueueType &value)
 Push non-blocking to the queue. More...
 
void PushNonBlocking (const QueueType &value)
 Push to the queue. More...
 
virtual size_t Size () const final
 Return the size of the queue. More...
 
virtual bool Empty () const final
 Return true if the queue is empty. More...
 
bool PushBlockingIfFull (const QueueType &value, size_t max_queue_size)
 Push to the queue if the size is less than max_queue_size, else block. More...
 
bool PushNonBlockingDroppingIfFull (const QueueType &value, size_t max_queue_size)
 Push to the queue. If full, drop the oldest entry. More...
 
bool Pop (QueueType *value)
 Get the oldest entry still in the queue. Blocking if queue is empty. More...
 
bool PopBlocking (QueueType *value)
 Get the oldest entry still in the queue. Blocking if queue is empty. More...
 
bool PopNonBlocking (QueueType *value)
 Get the oldest entry still in the queue. If queue is empty value is not altered. More...
 
bool PopTimeout (QueueType *value, int64_t timeout_nanoseconds)
 Get the oldest entry still in the queue. If the queue is empty wait for a given amount of time. If during this time an entry was pushed alter the value. If the queue is still empty, the value is not altered and it will return false. More...
 
bool getCopyOfFront (QueueType *value)
 Get a copy of the front / oldest element in the queue. If queue is empty value is not altered. The queue itself is not changed, i.e. the returned element is still in the queue. More...
 
bool getCopyOfFrontBlocking (QueueType *value)
 Get a copy of the front / oldest element in the queue. Blocking if queue is empty. The queue itself is not changed, i.e. the returned element is still in the queue. More...
 
bool getCopyOfBack (QueueType *value)
 Get a copy of the back / newest element in the queue. If queue is empty value is not altered. The queue itself is not changed, i.e. the returned element is still in the queue. More...
 

Public Attributes

pthread_mutex_t mutex_
 The queue mutex. More...
 
pthread_cond_t condition_empty_
 Condition variable to wait and signal that queue is not empty. More...
 
pthread_cond_t condition_full_
 Condition variable to wait and signal when an element is popped. More...
 
std::queue< QueueType > queue_
 Actual queue. More...
 
std::atomic_bool shutdown_
 Flag if shutdown is requested. More...
 

Friends

bool test_funcs (void *(*)(void *), void *(*)(void *), const std::string &, bool)
 

Detailed Description

template<typename QueueType>
class okvis::threadsafe::ThreadSafeQueue< QueueType >

Class that implements a threadsafe FIFO queue.

Template Parameters
QueueTypeDatatype that is safed in the queue.

Constructor & Destructor Documentation

template<typename QueueType>
okvis::threadsafe::ThreadSafeQueue< QueueType >::ThreadSafeQueue ( )
inline

Constructor.

template<typename QueueType>
virtual okvis::threadsafe::ThreadSafeQueue< QueueType >::~ThreadSafeQueue ( )
inlinevirtual

Destructor.

Member Function Documentation

template<typename QueueType>
virtual bool okvis::threadsafe::ThreadSafeQueue< QueueType >::Empty ( ) const
inlinefinalvirtual

Return true if the queue is empty.

template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::getCopyOfBack ( QueueType *  value)
inline

Get a copy of the back / newest element in the queue. If queue is empty value is not altered. The queue itself is not changed, i.e. the returned element is still in the queue.

Parameters
[out]valueNewest entry in queue if queue was not empty.
Returns
True if queue was not empty and value was updated.
template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::getCopyOfFront ( QueueType *  value)
inline

Get a copy of the front / oldest element in the queue. If queue is empty value is not altered. The queue itself is not changed, i.e. the returned element is still in the queue.

Parameters
[out]valueOldest entry in queue if queue was not empty.
Returns
True if queue was not empty and value was updated.
template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::getCopyOfFrontBlocking ( QueueType *  value)
inline

Get a copy of the front / oldest element in the queue. Blocking if queue is empty. The queue itself is not changed, i.e. the returned element is still in the queue.

Parameters
valueOldest entry in the queue.
Returns
False if shutdown is requested.
template<typename QueueType>
virtual void okvis::threadsafe::ThreadSafeQueue< QueueType >::NotifyAll ( ) const
inlinefinalvirtual

Notify all waiting threads. Only used in destructor and when shutting down.

template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::Pop ( QueueType *  value)
inline

Get the oldest entry still in the queue. Blocking if queue is empty.

Parameters
[out]valueOldest entry in queue.
Returns
False if shutdown is requested.
template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::PopBlocking ( QueueType *  value)
inline

Get the oldest entry still in the queue. Blocking if queue is empty.

Parameters
[out]valueOldest entry in queue.
Returns
False if shutdown is requested.
template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::PopNonBlocking ( QueueType *  value)
inline

Get the oldest entry still in the queue. If queue is empty value is not altered.

Parameters
[out]valueOldest entry in queue if queue was not empty.
Returns
True if queue was not empty.
template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::PopTimeout ( QueueType *  value,
int64_t  timeout_nanoseconds 
)
inline

Get the oldest entry still in the queue. If the queue is empty wait for a given amount of time. If during this time an entry was pushed alter the value. If the queue is still empty, the value is not altered and it will return false.

Parameters
[out]valueOldest entry in queue if queue was not empty.
timeout_nanosecondsMaximum amount of time to wait for an entry if queue is empty.
Returns
True if value was updated. False if queue was empty and no new entry was pushed during the given timeout.
template<typename QueueType>
void okvis::threadsafe::ThreadSafeQueue< QueueType >::Push ( const QueueType &  value)
inline

Push non-blocking to the queue.

template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::PushBlockingIfFull ( const QueueType &  value,
size_t  max_queue_size 
)
inline

Push to the queue if the size is less than max_queue_size, else block.

Parameters
[in]valueNew entry in queue.
[in]max_queue_sizeMaximum queue size.
Returns
False if shutdown is requested.
template<typename QueueType>
void okvis::threadsafe::ThreadSafeQueue< QueueType >::PushNonBlocking ( const QueueType &  value)
inline

Push to the queue.

template<typename QueueType>
bool okvis::threadsafe::ThreadSafeQueue< QueueType >::PushNonBlockingDroppingIfFull ( const QueueType &  value,
size_t  max_queue_size 
)
inline

Push to the queue. If full, drop the oldest entry.

Parameters
[in]valueNew entry in queue.
[in]max_queue_sizeMaximum queue size.
Returns
True if oldest was dropped because queue was full.
template<typename QueueType>
virtual void okvis::threadsafe::ThreadSafeQueue< QueueType >::Resume ( )
inlinefinalvirtual

Tell the queue to resume after a shutdown request.

template<typename QueueType>
virtual void okvis::threadsafe::ThreadSafeQueue< QueueType >::Shutdown ( )
inlinefinalvirtual

Tell the queue shut down. This will notify all threads to wake up.

template<typename QueueType>
virtual size_t okvis::threadsafe::ThreadSafeQueue< QueueType >::Size ( ) const
inlinefinalvirtual

Return the size of the queue.

Friends And Related Function Documentation

template<typename QueueType>
bool test_funcs ( void *  *)(void *,
void *  *)(void *,
const std::string &  ,
bool   
)
friend

Member Data Documentation

template<typename QueueType>
pthread_cond_t okvis::threadsafe::ThreadSafeQueue< QueueType >::condition_empty_
mutable

Condition variable to wait and signal that queue is not empty.

template<typename QueueType>
pthread_cond_t okvis::threadsafe::ThreadSafeQueue< QueueType >::condition_full_
mutable

Condition variable to wait and signal when an element is popped.

template<typename QueueType>
pthread_mutex_t okvis::threadsafe::ThreadSafeQueue< QueueType >::mutex_
mutable

The queue mutex.

template<typename QueueType>
std::queue<QueueType> okvis::threadsafe::ThreadSafeQueue< QueueType >::queue_

Actual queue.

template<typename QueueType>
std::atomic_bool okvis::threadsafe::ThreadSafeQueue< QueueType >::shutdown_

Flag if shutdown is requested.


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