Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Private Attributes | List of all members
orxonox::TclThreadList< T > Class Template Reference

A thread-safe implementation of a message queue, used by TclThreadManager. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/command/TclThreadList.h>

Public Member Functions

void clear ()
 Clears the list. More...
 
bool empty () const
 Returns true if the list is empty, false otherwise. More...
 
std::list< T > & getList ()
 Returns a reference to the list. More...
 
const std::list< T > & getList () const
 Returns a reference to the list. More...
 
boost::shared_mutex & getMutex () const
 Returns a reference to the mutex which might be useful if you want to iterate through the list (see getList()). More...
 
template<class InputIterator >
void insert (typename std::list< T >::iterator position, InputIterator begin, InputIterator end)
 Inserts new elements into the list. More...
 
bool is_in (const T &value) const
 Returns true if a given element is in the list, false otherwise. More...
 
void push_back (const T &value)
 Pushes a new element to the back of the list. More...
 
void push_front (const T &value)
 Pushes a new element to the front of the list. More...
 
size_t size () const
 Returns the size of the list. More...
 
bool try_pop_back (T *value)
 Pops and returns the back element if there's at least one element in the list. More...
 
bool try_pop_front (T *value)
 Pops and returns the front element if there's at least one element in the list. More...
 
void wait_and_pop_back (T *value)
 Waits until the list contains at least one element and then pops and returns the back element. More...
 
void wait_and_pop_front (T *value)
 Waits until the list contains at least one element and then pops and returns the front element. More...
 

Private Attributes

boost::condition_variable_any condition_
 A condition variable to wake threads waiting for the mutex to become ready. More...
 
std::list< T > list_
 A standard list for type T. More...
 
boost::shared_mutex mutex_
 A mutex to grant exclusive access to the list. More...
 

Detailed Description

template<class T>
class orxonox::TclThreadList< T >

A thread-safe implementation of a message queue, used by TclThreadManager.

Member Function Documentation

template<class T >
void orxonox::TclThreadList< T >::clear ( )

Clears the list.

A unique_lock is needed.

template<class T >
bool orxonox::TclThreadList< T >::empty ( ) const

Returns true if the list is empty, false otherwise.

A shared_lock is needed.

Warning: Don't change the list based on the result of empty(). Use an atomic function instead. Other threads may change the list beween your call to empty() and your further actions, so be careful and use this function only if you really want nothing else than just if the list is empty or not.

template<class T>
std::list<T>& orxonox::TclThreadList< T >::getList ( )
inline

Returns a reference to the list.

Don't forget to lock the mutex (see getMutex).

template<class T>
const std::list<T>& orxonox::TclThreadList< T >::getList ( ) const
inline

Returns a reference to the list.

Don't forget to lock the mutex (see getMutex).

template<class T>
boost::shared_mutex& orxonox::TclThreadList< T >::getMutex ( ) const
inline

Returns a reference to the mutex which might be useful if you want to iterate through the list (see getList()).

template<class T>
template<class InputIterator >
void orxonox::TclThreadList< T >::insert ( typename std::list< T >::iterator  position,
InputIterator  begin,
InputIterator  end 
)

Inserts new elements into the list.

A unique_lock is needed.

template<class T>
bool orxonox::TclThreadList< T >::is_in ( const T &  value) const

Returns true if a given element is in the list, false otherwise.

A shared_lock is needed.

Warning: The result of this function might be wrong just one instruction after the call. Use this function just to get information about a temporary snapshot and don't change the list based on the result of this function.

template<class T>
void orxonox::TclThreadList< T >::push_back ( const T &  value)

Pushes a new element to the back of the list.

A unique_lock is needed.

template<class T>
void orxonox::TclThreadList< T >::push_front ( const T &  value)

Pushes a new element to the front of the list.

A unique_lock is needed.

template<class T >
size_t orxonox::TclThreadList< T >::size ( ) const

Returns the size of the list.

A shared_lock is needed.

Warning: Don't change the list based on the result of size(). Use an atomic function instead. Other threads may change the list beween your call to size() and your further actions, so be careful and use this function only if you really want nothing else than just the size of the list.

template<class T>
bool orxonox::TclThreadList< T >::try_pop_back ( T *  value)

Pops and returns the back element if there's at least one element in the list.

Parameters
valueThe back value will be stored in the variable referenced by this pointer.
Returns
Returns true if there was at least one element in the list (which got poped). If the list was empty, false is returned immediately.

Needs a unique_lock if there's an element to pop. If not, shared_lock is sufficient.

template<class T>
bool orxonox::TclThreadList< T >::try_pop_front ( T *  value)

Pops and returns the front element if there's at least one element in the list.

Parameters
valueThe front value will be stored in the variable referenced by this pointer.
Returns
Returns true if there was at least one element in the list (which got poped). If the list was empty, false is returned immediately.

Needs a unique_lock if there's an element to pop. If not, shared_lock is sufficient.

template<class T>
void orxonox::TclThreadList< T >::wait_and_pop_back ( T *  value)

Waits until the list contains at least one element and then pops and returns the back element.

Parameters
valueThe back value will be stored in the variable referenced by this pointer.
template<class T>
void orxonox::TclThreadList< T >::wait_and_pop_front ( T *  value)

Waits until the list contains at least one element and then pops and returns the front element.

Parameters
valueThe front value will be stored in the variable referenced by this pointer.

Member Data Documentation

template<class T>
boost::condition_variable_any orxonox::TclThreadList< T >::condition_
private

A condition variable to wake threads waiting for the mutex to become ready.

template<class T>
std::list<T> orxonox::TclThreadList< T >::list_
private

A standard list for type T.

template<class T>
boost::shared_mutex orxonox::TclThreadList< T >::mutex_
mutableprivate

A mutex to grant exclusive access to the list.


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