Orxonox
0.0.5 Codename: Arcturus
|
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... | |
A thread-safe implementation of a message queue, used by TclThreadManager.
void orxonox::TclThreadList< T >::clear | ( | ) |
Clears the list.
A unique_lock is needed.
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.
|
inline |
Returns a reference to the list.
Don't forget to lock the mutex (see getMutex).
|
inline |
Returns a reference to the list.
Don't forget to lock the mutex (see getMutex).
|
inline |
Returns a reference to the mutex which might be useful if you want to iterate through the list (see getList()).
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.
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.
void orxonox::TclThreadList< T >::push_back | ( | const T & | value | ) |
Pushes a new element to the back of the list.
A unique_lock is needed.
void orxonox::TclThreadList< T >::push_front | ( | const T & | value | ) |
Pushes a new element to the front of the list.
A unique_lock is needed.
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.
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.
value | The back value will be stored in the variable referenced by this pointer. |
Needs a unique_lock if there's an element to pop. If not, shared_lock is sufficient.
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.
value | The front value will be stored in the variable referenced by this pointer. |
Needs a unique_lock if there's an element to pop. If not, shared_lock is sufficient.
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.
value | The back value will be stored in the variable referenced by this pointer. |
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.
value | The front value will be stored in the variable referenced by this pointer. |
|
private |
A condition variable to wake threads waiting for the mutex to become ready.
|
private |
A standard list for type T.
|
mutableprivate |
A mutex to grant exclusive access to the list.