Sirikata
|
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>
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 () | |
ThreadSafeQueueWithNotification & | operator= (const ThreadSafeQueueWithNotification &other) |
ThreadSafeQueueWithNotification (const ThreadSafeQueueWithNotification &other) | |
Private Attributes | |
ThreadSafeQueue< T > | mQueue |
Notification | mCallback |
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.
typedef std::tr1::function<void()> Sirikata::ThreadSafeQueueWithNotification< T >::Notification |
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.
Sirikata::ThreadSafeQueueWithNotification< T >::~ThreadSafeQueueWithNotification | ( | ) | [inline] |
Sirikata::ThreadSafeQueueWithNotification< T >::ThreadSafeQueueWithNotification | ( | ) | [private] |
Sirikata::ThreadSafeQueueWithNotification< T >::ThreadSafeQueueWithNotification | ( | const ThreadSafeQueueWithNotification< T > & | other | ) | [private] |
void Sirikata::ThreadSafeQueueWithNotification< T >::blockingPop | ( | T & | retval | ) | [inline] |
bool Sirikata::ThreadSafeQueueWithNotification< T >::empty | ( | ) | [inline] |
Returns true if the queue is empty.
Referenced by Sirikata::OH::SQLiteStorage::processTransactions(), Sirikata::ObjectSegmentation::trySendMigAcks(), and Sirikata::ObjectSegmentation::~ObjectSegmentation().
ThreadSafeQueueWithNotification& Sirikata::ThreadSafeQueueWithNotification< T >::operator= | ( | const ThreadSafeQueueWithNotification< T > & | other | ) | [private] |
bool Sirikata::ThreadSafeQueueWithNotification< T >::pop | ( | T & | ret | ) | [inline] |
void Sirikata::ThreadSafeQueueWithNotification< T >::popAll | ( | std::deque< T > * | popResults | ) | [inline] |
bool Sirikata::ThreadSafeQueueWithNotification< T >::probablyEmpty | ( | ) | [inline] |
Referenced by Sirikata::ThreadSafeQueueWithNotification< TransactionData >::empty().
void Sirikata::ThreadSafeQueueWithNotification< T >::push | ( | const T & | value | ) | [inline] |
void Sirikata::ThreadSafeQueueWithNotification< T >::pushMultiple | ( | const std::deque< T > & | values | ) | [inline] |
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.
void Sirikata::ThreadSafeQueueWithNotification< T >::swap | ( | std::deque< T > & | swapWith | ) | [inline] |
Referenced by Sirikata::OH::Manual::ObjectQueryHandler::handleDeliverEvents().
Notification Sirikata::ThreadSafeQueueWithNotification< T >::mCallback [private] |
ThreadSafeQueue<T> Sirikata::ThreadSafeQueueWithNotification< T >::mQueue [private] |
Referenced by Sirikata::ThreadSafeQueueWithNotification< TransactionData >::blockingPop(), Sirikata::ThreadSafeQueueWithNotification< TransactionData >::pop(), Sirikata::ThreadSafeQueueWithNotification< TransactionData >::popAll(), Sirikata::ThreadSafeQueueWithNotification< TransactionData >::probablyEmpty(), Sirikata::ThreadSafeQueueWithNotification< TransactionData >::push(), Sirikata::ThreadSafeQueueWithNotification< TransactionData >::pushMultiple(), Sirikata::ThreadSafeQueueWithNotification< TransactionData >::size(), and Sirikata::ThreadSafeQueueWithNotification< TransactionData >::swap().