Orocos Real-Time Toolkit
2.8.3
|
A simple lock-free list implementation to append or erase data of type T. More...
#include <rtt/internal/ListLockFree.hpp>
Public Types | |
typedef T | value_t |
Public Member Functions | |
ListLockFree (unsigned int lsize, unsigned int threads=ORONUM_OS_MAX_THREADS) | |
Create a lock-free list wich can store lsize elements. More... | |
~ListLockFree () | |
size_t | capacity () const |
Returns the maximum number of elements this list can hold. More... | |
size_t | size () const |
Returns the current number of elements in this list. More... | |
bool | empty () const |
Returns true if this list is empty. More... | |
void | grow (size_t items=1) |
Grow the capacity to contain at least n additional items. More... | |
void | shrink (size_t items=1) |
Shrink the capacity with at most n items. More... | |
void | reserve (size_t lsize) |
Reserve a capacity for this list. More... | |
void | clear () |
Clears all elements in the list. More... | |
bool | append (value_t item) |
Append a single value to the list. More... | |
value_t | front () const |
Returns the first element of the list. More... | |
value_t | back () const |
Returns the last element of the list. More... | |
size_t | append (const std::vector< T > &items) |
Append a sequence of values to the list. More... | |
bool | erase (value_t item) |
Erase a value from the list. More... | |
template<typename Pred > | |
bool | delete_if (Pred pred) |
Erase a value from the list. More... | |
template<class Function > | |
void | apply (Function func) |
Apply a function to the elements of the whole list. More... | |
template<class Function > | |
void | apply_and_blank (Function func, value_t blank) |
Apply a function to the non-blanked elements of the list. More... | |
bool | erase_and_blank (value_t item, value_t blank) |
Erase an element from the list and blank it if possible. More... | |
template<class Function > | |
value_t | find_if (Function func, value_t blank=value_t()) |
Find an item in the list such that func( item ) == true. More... | |
Public Attributes | |
const unsigned int | MAX_THREADS |
The maximum number of threads. More... | |
A simple lock-free list implementation to append or erase data of type T.
If T is a value type, no memory allocation is done during appending or erasing. The maximum number of threads which can access this object is defined by MAX_THREADS.
T | The value type to be stored in the list. If T is a type that does memory allocation or deallocation in copy-constructor or destructor, certain functions of this list will not be real-time. Example : ListLockFree is a list which holds values of type A. |
Definition at line 85 of file ListLockFree.hpp.
typedef T RTT::internal::ListLockFree< T >::value_t |
Definition at line 95 of file ListLockFree.hpp.
|
inline |
Create a lock-free list wich can store lsize elements.
lsize | the capacity of the list. |
threads | the number of threads which may concurrently read or write this buffer. Defaults to ORONUM_OS_MAX_THREADS, but you may lower this number in case not all threads will read this buffer. A lower number will consume less memory. ' |
Definition at line 164 of file ListLockFree.hpp.
|
inline |
Definition at line 171 of file ListLockFree.hpp.
|
inline |
Append a single value to the list.
This function calls the copy-constructor of item and may call the destructor of item
item | the value to write |
Definition at line 344 of file ListLockFree.hpp.
Referenced by RTT::corba::CorbaDispatcher::dispatchChannel().
|
inline |
Append a sequence of values to the list.
items | the values to append. |
Definition at line 401 of file ListLockFree.hpp.
|
inline |
Apply a function to the elements of the whole list.
func | The function to apply. |
Definition at line 524 of file ListLockFree.hpp.
Referenced by RTT::internal::SignalBase::disconnect(), and RTT::corba::CorbaDispatcher::dispatchChannel().
|
inline |
Apply a function to the non-blanked elements of the list.
If during an apply_and_blank, the erase_and_blank function is called, that element will not be subject to func if not yet processed. You must not call this function concurrently from multiple threads.
func | The function to apply. |
blank | The 'blank' item. Each item of this list will be compared to this item using operator==(), if it matches, it is considered blank, and func is not applied. |
Definition at line 552 of file ListLockFree.hpp.
|
inline |
Returns the last element of the list.
Definition at line 385 of file ListLockFree.hpp.
|
inline |
Returns the maximum number of elements this list can hold.
Definition at line 178 of file ListLockFree.hpp.
|
inline |
Clears all elements in the list.
Definition at line 316 of file ListLockFree.hpp.
|
inline |
Erase a value from the list.
function | each elements for which pred returns true are removed |
Definition at line 480 of file ListLockFree.hpp.
|
inline |
Returns true if this list is empty.
Definition at line 206 of file ListLockFree.hpp.
Referenced by RTT::internal::SignalBase::destroy(), and RTT::corba::CorbaDispatcher::loop().
|
inline |
Erase a value from the list.
item | is to be erased from the list. |
Definition at line 438 of file ListLockFree.hpp.
Referenced by RTT::corba::CorbaDispatcher::cancelChannel(), RTT::internal::SignalBase::destroy(), and RTT::corba::CorbaDispatcher::loop().
|
inline |
Erase an element from the list and blank it if possible.
If during an apply_and_blank, the erase_and_blank function is called, that element will not be subject to func if not yet processed. You may call this function concurrently from multiple threads.
item | The item to erase from the list. |
blank | The 'blank' item to use to blank item from the list. |
Definition at line 597 of file ListLockFree.hpp.
|
inline |
Find an item in the list such that func( item ) == true.
blank | The value to return if not found. |
Definition at line 626 of file ListLockFree.hpp.
|
inline |
Returns the first element of the list.
Definition at line 373 of file ListLockFree.hpp.
Referenced by RTT::internal::SignalBase::destroy(), and RTT::corba::CorbaDispatcher::loop().
|
inline |
Grow the capacity to contain at least n additional items.
This method tries to avoid too much re-allocations, by growing a bit more than required every N invocations and growing nothing in between.
items | The number of items to at least additionally reserve. |
Definition at line 224 of file ListLockFree.hpp.
|
inline |
Reserve a capacity for this list.
If you wish to invoke this method concurrently, guard it with a mutex. The other methods may be invoked concurrently with this method.
lsize | the minimal number of items this list will be able to hold. Will not drop below the current capacity() and this method will do nothing if lsize < this->capacity(). @ Not real-time if lsize <= this->capacity(). |
Definition at line 252 of file ListLockFree.hpp.
Referenced by RTT::internal::SignalBase::reserve().
|
inline |
Shrink the capacity with at most n items.
This method does not actually free memory, it just prevents a (number of) subsequent grow() invocations to allocate more memory.
items | The number of items to at most remove from the capacity. |
Definition at line 238 of file ListLockFree.hpp.
|
inline |
Returns the current number of elements in this list.
Definition at line 192 of file ListLockFree.hpp.
const unsigned int RTT::internal::ListLockFree< T >::MAX_THREADS |
The maximum number of threads.
The number of threads which may concurrently access this buffer.
Definition at line 93 of file ListLockFree.hpp.