Sirikata
Classes | Public Member Functions | Protected Types | Protected Attributes | Private Member Functions | Static Private Member Functions | Friends
Sirikata::ThreadSafeQueue< T > Class Template Reference

ThreadSafeQueue provides a queue interface whose operations -- push, pop, empty -- are thread-safe. More...

#include <ThreadSafeQueue.hpp>

Collaboration diagram for Sirikata::ThreadSafeQueue< T >:

List of all members.

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

ThreadSafeQueueoperator= (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

Detailed Description

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

ThreadSafeQueue provides a queue interface whose operations -- push, pop, empty -- are thread-safe.


Member Typedef Documentation

template<typename T>
typedef std::deque<T> Sirikata::ThreadSafeQueue< T >::ListType [protected]

Constructor & Destructor Documentation

template<typename T>
Sirikata::ThreadSafeQueue< T >::ThreadSafeQueue ( const ThreadSafeQueue< T > &  other) [inline, private]
template<typename T>
Sirikata::ThreadSafeQueue< T >::ThreadSafeQueue ( ) [inline]
template<typename T>
Sirikata::ThreadSafeQueue< T >::~ThreadSafeQueue ( ) [inline]

Member Function Documentation

template<typename T>
void Sirikata::ThreadSafeQueue< T >::blockingPop ( T &  retval) [inline]
template<typename T>
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.

Returns:
a reference to this class
template<typename T>
bool Sirikata::ThreadSafeQueue< T >::pop ( T &  ret) [inline]

Pops the front element from the queue and places it in ret.

Parameters:
retstorage for the popped element
Returns:
true if an element was popped, false if the queue was empty

Reimplemented in Sirikata::SizedThreadSafeQueue< RawRequest >, Sirikata::SizedThreadSafeQueue< Message * >, Sirikata::SizedThreadSafeQueue< ConnectionIDObjectMessagePair >, Sirikata::SizedThreadSafeQueue< QueuedMessage >, Sirikata::SizedThreadSafeQueue< TimestampedChunk >, and Sirikata::SizedThreadSafeQueue< Chunk *, CountResourceMonitor >.

template<typename T>
void Sirikata::ThreadSafeQueue< T >::popAll ( std::deque< T > *  popResults) [inline]
template<typename T>
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.

Returns:
true if the efficient check indicates the queue is empty

Reimplemented in Sirikata::SizedThreadSafeQueue< RawRequest >, Sirikata::SizedThreadSafeQueue< Message * >, Sirikata::SizedThreadSafeQueue< ConnectionIDObjectMessagePair >, Sirikata::SizedThreadSafeQueue< QueuedMessage >, Sirikata::SizedThreadSafeQueue< TimestampedChunk >, and Sirikata::SizedThreadSafeQueue< Chunk *, CountResourceMonitor >.

template<typename T>
int32 Sirikata::ThreadSafeQueue< T >::push ( const T &  value) [inline]
template<typename T>
int32 Sirikata::ThreadSafeQueue< T >::pushMultiple ( const std::deque< T > &  values) [inline]

Push multiple values onto the queue, only locking once.

Parameters:
valuesqueue holding values to push
template<typename T>
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().

template<typename T>
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.

Parameters:
swapWitha deque to swap elements with

Referenced by Sirikata::ThreadSafeQueue< T >::NodeIterator::NodeIterator(), Sirikata::LibproxProximity::poll(), Sirikata::LibproxManualProximity::poll(), and Sirikata::ThreadSafeQueue< TransactionData >::popAll().

template<typename T>
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

Parameters:
thusis a ThreadSafeQueue pointer: the queue to be operated upon
vretvalis the item that should be filled with data to be popped from the queue
Returns:
true if there is no data in the ThreadSafeQueue and data must be waited for

Friends And Related Function Documentation

template<typename T>
friend class NodeIterator [friend]

Member Data Documentation

template<typename T>
ThreadSafeQueueNS::Condition* Sirikata::ThreadSafeQueue< T >::mCond [protected]
template<typename T>
ListType Sirikata::ThreadSafeQueue< T >::mList [protected]
template<typename T>
ThreadSafeQueueNS::Lock* Sirikata::ThreadSafeQueue< T >::mLock [protected]

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