Sirikata
Public Types | Public Member Functions | Private Member Functions | Private Attributes
Sirikata::ThreadSafeQueueWithNotification< T > Class Template Reference

ThreadSafeQueueWithNotification is a ThreadSafeQueue that also allows the user to specify a notification callback which is invoked when an item is pushed on the queue, causing it to go from empty to non-empty (note that a notification is not (necessarily) generated for every single push). More...

#include <ThreadSafeQueueWithNotification.hpp>

Collaboration diagram for Sirikata::ThreadSafeQueueWithNotification< T >:

List of all members.

Public Types

typedef std::tr1::function< void()> Notification

Public Member Functions

 ThreadSafeQueueWithNotification (const Notification &cb)
 Create a new ThreadSafeQueueWithNotification which will invoke the given notification callback when a push() causes the queue to become non-empty.
 ~ThreadSafeQueueWithNotification ()
void push (const T &value)
void pushMultiple (const std::deque< T > &values)
bool pop (T &ret)
void blockingPop (T &retval)
void swap (std::deque< T > &swapWith)
void popAll (std::deque< T > *popResults)
bool probablyEmpty ()
bool empty ()
 Returns true if the queue is empty.
int32 size ()
 Get the current size of the queue.

Private Member Functions

 ThreadSafeQueueWithNotification ()
ThreadSafeQueueWithNotificationoperator= (const ThreadSafeQueueWithNotification &other)
 ThreadSafeQueueWithNotification (const ThreadSafeQueueWithNotification &other)

Private Attributes

ThreadSafeQueue< T > mQueue
Notification mCallback

Detailed Description

template<typename T>
class Sirikata::ThreadSafeQueueWithNotification< T >

ThreadSafeQueueWithNotification is a ThreadSafeQueue that also allows the user to specify a notification callback which is invoked when an item is pushed on the queue, causing it to go from empty to non-empty (note that a notification is not (necessarily) generated for every single push).

This mechanism allows the "receiving" thread to "wait" on this queue efficiently, aggregating handling of elements if more are inserted before the notification is handled. This also allows a single receiving thread to "wait" on multiple ThreadSafeQueues.

Note that notifications are generated from the thread or strand in which the push occurs. If you want to receive them in another thread, you probably want to use a callback wrapped by a strand or which performs a post to an IOService, depending on your setup.

Finally, note that the notification mechanism is conservative: it is possible that, due to concurrent pushing and popping, it is possible an extra notification will be generated, resulting in a notification callback being invoked when nothing remains in the queue. Therefore the user should not assume the queue is non-empty when a notification callback is invoked.


Member Typedef Documentation

template<typename T>
typedef std::tr1::function<void()> Sirikata::ThreadSafeQueueWithNotification< T >::Notification

Constructor & Destructor Documentation

template<typename T>
Sirikata::ThreadSafeQueueWithNotification< T >::ThreadSafeQueueWithNotification ( const Notification cb) [inline]

Create a new ThreadSafeQueueWithNotification which will invoke the given notification callback when a push() causes the queue to become non-empty.


Member Function Documentation

template<typename T>
void Sirikata::ThreadSafeQueueWithNotification< T >::blockingPop ( T &  retval) [inline]
template<typename T>
bool Sirikata::ThreadSafeQueueWithNotification< T >::empty ( ) [inline]
template<typename T>
ThreadSafeQueueWithNotification& Sirikata::ThreadSafeQueueWithNotification< T >::operator= ( const ThreadSafeQueueWithNotification< T > &  other) [private]
template<typename T>
bool Sirikata::ThreadSafeQueueWithNotification< T >::pop ( T &  ret) [inline]
template<typename T>
void Sirikata::ThreadSafeQueueWithNotification< T >::popAll ( std::deque< T > *  popResults) [inline]
template<typename T>
bool Sirikata::ThreadSafeQueueWithNotification< T >::probablyEmpty ( ) [inline]
template<typename T>
void Sirikata::ThreadSafeQueueWithNotification< T >::push ( const T &  value) [inline]
template<typename T>
void Sirikata::ThreadSafeQueueWithNotification< T >::pushMultiple ( const std::deque< T > &  values) [inline]
template<typename T>
int32 Sirikata::ThreadSafeQueueWithNotification< T >::size ( ) [inline]

Get the current size of the queue.

This could immediately change, so this is only useful for monitoring the queue: you should not use it, for example, to tell whether the queue is empty.

template<typename T>
void Sirikata::ThreadSafeQueueWithNotification< T >::swap ( std::deque< T > &  swapWith) [inline]

Member Data Documentation

template<typename T>
ThreadSafeQueue<T> Sirikata::ThreadSafeQueueWithNotification< T >::mQueue [private]

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