Sirikata
|
ThreadSafeQueue provides a queue interface whose operations -- push, pop, empty -- are thread-safe. More...
#include <ThreadSafeQueue.hpp>
Classes | |
class | NodeIterator |
Public Member Functions | |
ThreadSafeQueue () | |
~ThreadSafeQueue () | |
void | swap (std::deque< T > &swapWith) |
Swap the contents of this queue with the one specified. | |
void | popAll (std::deque< T > *popResults) |
Pops all elements currently in the ThreadSafeQueue into popResults. | |
int32 | push (const T &value) |
Push a value onto the queue. | |
int32 | pushMultiple (const std::deque< T > &values) |
Push multiple values onto the queue, only locking once. | |
bool | pop (T &ret) |
Pops the front element from the queue and places it in ret. | |
void | blockingPop (T &retval) |
Pop an element from the queue, blocking until an element is available if the queue is currently empty. | |
bool | probablyEmpty () |
Checks if the queue is probably empty, without any locking. | |
int32 | size () |
Get the current size of the queue. | |
Protected Types | |
typedef std::deque< T > | ListType |
Protected Attributes | |
ThreadSafeQueueNS::Lock * | mLock |
ListType | mList |
ThreadSafeQueueNS::Condition * | mCond |
Private Member Functions | |
ThreadSafeQueue & | operator= (const ThreadSafeQueue &other) |
Private function to copy a ThreadSafeQueue to another Must pick a particular order, in this case pointer order, to acquire the locks Must copy the list, and unlock if an exception is thrown. | |
ThreadSafeQueue (const ThreadSafeQueue &other) | |
Static Private Member Functions | |
static bool | waitCheck (void *thus, void *vretval) |
This function is a helper function for a condition wait on empty data Assumes the mLock is taken. | |
Friends | |
class | NodeIterator |
ThreadSafeQueue provides a queue interface whose operations -- push, pop, empty -- are thread-safe.
typedef std::deque<T> Sirikata::ThreadSafeQueue< T >::ListType [protected] |
Sirikata::ThreadSafeQueue< T >::ThreadSafeQueue | ( | const ThreadSafeQueue< T > & | other | ) | [inline, private] |
Sirikata::ThreadSafeQueue< T >::ThreadSafeQueue | ( | ) | [inline] |
Sirikata::ThreadSafeQueue< T >::~ThreadSafeQueue | ( | ) | [inline] |
void Sirikata::ThreadSafeQueue< T >::blockingPop | ( | T & | retval | ) | [inline] |
Pop an element from the queue, blocking until an element is available if the queue is currently empty.
retval | storage for the popped element |
Reimplemented in Sirikata::SizedThreadSafeQueue< RawRequest >, Sirikata::SizedThreadSafeQueue< Message * >, Sirikata::SizedThreadSafeQueue< ConnectionIDObjectMessagePair >, Sirikata::SizedThreadSafeQueue< QueuedMessage >, Sirikata::SizedThreadSafeQueue< TimestampedChunk >, and Sirikata::SizedThreadSafeQueue< Chunk *, CountResourceMonitor >.
Referenced by Sirikata::Transfer::SimpleTransferPool::getRequest(), Sirikata::Transfer::AggregatedTransferPool::getRequest(), Sirikata::Transfer::DiskManager::workerThread(), and Sirikata::Transfer::DiskCacheLayer::workerThread().
ThreadSafeQueue& Sirikata::ThreadSafeQueue< T >::operator= | ( | const ThreadSafeQueue< T > & | other | ) | [inline, private] |
Private function to copy a ThreadSafeQueue to another Must pick a particular order, in this case pointer order, to acquire the locks Must copy the list, and unlock if an exception is thrown.
bool Sirikata::ThreadSafeQueue< T >::pop | ( | T & | ret | ) | [inline] |
Pops the front element from the queue and places it in ret.
ret | storage for the popped element |
Reimplemented in Sirikata::SizedThreadSafeQueue< RawRequest >, Sirikata::SizedThreadSafeQueue< Message * >, Sirikata::SizedThreadSafeQueue< ConnectionIDObjectMessagePair >, Sirikata::SizedThreadSafeQueue< QueuedMessage >, Sirikata::SizedThreadSafeQueue< TimestampedChunk >, and Sirikata::SizedThreadSafeQueue< Chunk *, CountResourceMonitor >.
void Sirikata::ThreadSafeQueue< T >::popAll | ( | std::deque< T > * | popResults | ) | [inline] |
Pops all elements currently in the ThreadSafeQueue into popResults.
Any elements currently in popResults will be discarded.
popResults | a deque to place popped elements in |
Reimplemented in Sirikata::SizedThreadSafeQueue< RawRequest >, Sirikata::SizedThreadSafeQueue< Message * >, Sirikata::SizedThreadSafeQueue< ConnectionIDObjectMessagePair >, Sirikata::SizedThreadSafeQueue< QueuedMessage >, Sirikata::SizedThreadSafeQueue< TimestampedChunk >, and Sirikata::SizedThreadSafeQueue< Chunk *, CountResourceMonitor >.
bool Sirikata::ThreadSafeQueue< T >::probablyEmpty | ( | ) | [inline] |
Checks if the queue is probably empty, without any locking.
Most of the time this is as good as checking empty() since the value of empty() could change immediately after the call returns since the queue is then unlocked.
Reimplemented in Sirikata::SizedThreadSafeQueue< RawRequest >, Sirikata::SizedThreadSafeQueue< Message * >, Sirikata::SizedThreadSafeQueue< ConnectionIDObjectMessagePair >, Sirikata::SizedThreadSafeQueue< QueuedMessage >, Sirikata::SizedThreadSafeQueue< TimestampedChunk >, and Sirikata::SizedThreadSafeQueue< Chunk *, CountResourceMonitor >.
int32 Sirikata::ThreadSafeQueue< T >::push | ( | const T & | value | ) | [inline] |
Push a value onto the queue.
value | the value to push |
Referenced by Sirikata::Transfer::DiskManager::addRequest(), Sirikata::Transfer::SimpleTransferPool::addRequest(), Sirikata::Transfer::AggregatedTransferPool::addRequest(), Sirikata::Transfer::SimpleTransferPool::deleteRequest(), Sirikata::Transfer::AggregatedTransferPool::deleteRequest(), Sirikata::LibproxProximity::generateServerQueryEvents(), Sirikata::LibproxManualProximity::queryHasEvents(), Sirikata::LibproxManualProximity::sendReplicatedClientProxMessage(), Sirikata::Transfer::SimpleTransferPool::updatePriority(), Sirikata::Transfer::AggregatedTransferPool::updatePriority(), Sirikata::Transfer::AggregatedTransferPool::~AggregatedTransferPool(), and Sirikata::Transfer::DiskManager::~DiskManager().
int32 Sirikata::ThreadSafeQueue< T >::pushMultiple | ( | const std::deque< T > & | values | ) | [inline] |
Push multiple values onto the queue, only locking once.
values | queue holding values to push |
int32 Sirikata::ThreadSafeQueue< 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.
Referenced by Sirikata::LibproxProximity::commandProperties().
void Sirikata::ThreadSafeQueue< T >::swap | ( | std::deque< T > & | swapWith | ) | [inline] |
Swap the contents of this queue with the one specified.
Note that this differs from popAll -- any elements currently in the queue being swapped will be in the ThreadSafeQueue when the operation completes.
swapWith | a deque to swap elements with |
Referenced by Sirikata::ThreadSafeQueue< T >::NodeIterator::NodeIterator(), Sirikata::LibproxProximity::poll(), Sirikata::LibproxManualProximity::poll(), and Sirikata::ThreadSafeQueue< TransactionData >::popAll().
static bool Sirikata::ThreadSafeQueue< T >::waitCheck | ( | void * | thus, |
void * | vretval | ||
) | [inline, static, private] |
This function is a helper function for a condition wait on empty data Assumes the mLock is taken.
Check if the list is empty--if so return true to wait longer. If not empty pop the front value and store the value in the value there
thus | is a ThreadSafeQueue pointer: the queue to be operated upon |
vretval | is the item that should be filled with data to be popped from the queue |
friend class NodeIterator [friend] |
ThreadSafeQueueNS::Condition* Sirikata::ThreadSafeQueue< T >::mCond [protected] |
Referenced by Sirikata::ThreadSafeQueue< TransactionData >::blockingPop(), Sirikata::ThreadSafeQueue< TransactionData >::push(), Sirikata::ThreadSafeQueue< TransactionData >::pushMultiple(), Sirikata::ThreadSafeQueue< TransactionData >::ThreadSafeQueue(), and Sirikata::ThreadSafeQueue< TransactionData >::~ThreadSafeQueue().
ListType Sirikata::ThreadSafeQueue< T >::mList [protected] |
Referenced by Sirikata::ThreadSafeQueue< TransactionData >::operator=(), Sirikata::ThreadSafeQueue< TransactionData >::pop(), Sirikata::ThreadSafeQueue< TransactionData >::probablyEmpty(), Sirikata::ThreadSafeQueue< TransactionData >::push(), Sirikata::ThreadSafeQueue< TransactionData >::pushMultiple(), Sirikata::ThreadSafeQueue< TransactionData >::size(), Sirikata::ThreadSafeQueue< TransactionData >::swap(), Sirikata::ThreadSafeQueue< TransactionData >::ThreadSafeQueue(), and Sirikata::ThreadSafeQueue< TransactionData >::waitCheck().
ThreadSafeQueueNS::Lock* Sirikata::ThreadSafeQueue< T >::mLock [protected] |
Referenced by Sirikata::ThreadSafeQueue< TransactionData >::blockingPop(), Sirikata::ThreadSafeQueue< TransactionData >::operator=(), Sirikata::ThreadSafeQueue< TransactionData >::pop(), Sirikata::ThreadSafeQueue< TransactionData >::push(), Sirikata::ThreadSafeQueue< TransactionData >::pushMultiple(), Sirikata::ThreadSafeQueue< TransactionData >::swap(), Sirikata::ThreadSafeQueue< TransactionData >::ThreadSafeQueue(), and Sirikata::ThreadSafeQueue< TransactionData >::~ThreadSafeQueue().