ListLockFree Class Template Reference

#include <rtt/ListLockFree.hpp>

List of all members.


Detailed Description

template<class T>
class RTT::ListLockFree< T >

A simple lock-free list implementation to append or erase data of type T.

No memory allocation is done during read or write, but the maximum number of threads which can access this object is defined by MAX_THREADS.

Parameters:
T The value type to be stored in the list. Example : ListLockFree is a list which holds values of type A.

Definition at line 83 of file 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.
 ~ListLockFree ()
size_t capacity () const
size_t size () const
bool empty () const
void grow (size_t items=1)
 Grow the capacity to contain at least n additional items.
void shrink (size_t items=1)
 Shrink the capacity with at most n items.
void reserve (size_t lsize)
 Reserve a capacity for this list.
void clear ()
bool append (value_t item)
 Append a single value to the list.
value_t front () const
 Returns the first element of the list.
value_t back () const
 Returns the last element of the list.
size_t append (const std::vector< T > &items)
 Append a sequence of values to the list.
bool erase (value_t item)
 Erase a value from the list.
template<class Function>
void apply (Function func)
 Apply a function to the elements of the whole list.
template<class Function>
void apply_and_blank (Function func, value_t blank)
 Apply a function to the non-blanked elements of the list.
bool erase_and_blank (value_t item, value_t blank)
 Erase an element from the list and blank it if possible.
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.

Public Attributes

const unsigned int MAX_THREADS

Constructor & Destructor Documentation

ListLockFree ( unsigned int  lsize,
unsigned int  threads = ORONUM_OS_MAX_THREADS 
) [inline]

Create a lock-free list wich can store lsize elements.

Parameters:
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 162 of file ListLockFree.hpp.

References RTT::OS::threads.


Member Function Documentation

void grow ( size_t  items = 1  )  [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.

Parameters:
items The number of items to at least additionally reserve.

Definition at line 209 of file ListLockFree.hpp.

References ListLockFree::reserve().

Referenced by ProgramProcessor::loadProgram(), StateMachineProcessor::recursiveLoadStateMachine(), and EventProcessor::setup().

void shrink ( size_t  items = 1  )  [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.

Parameters:
items The number of items to at most remove from the capacity.

Definition at line 222 of file ListLockFree.hpp.

Referenced by EventProcessor::destroyed(), StateMachineProcessor::recursiveUnloadStateMachine(), and ProgramProcessor::unloadProgram().

void reserve ( size_t  lsize  )  [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.

Parameters:
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().

Definition at line 235 of file ListLockFree.hpp.

References ListLockFree::capacity(), and RTT::OS::CAS().

Referenced by ListLockFree::grow().

bool append ( value_t  item  )  [inline]

Append a single value to the list.

Parameters:
d the value to write
Returns:
false if the list is full.

Definition at line 318 of file ListLockFree.hpp.

References RTT::OS::CAS().

Referenced by ProgramProcessor::loadProgram(), StateMachineProcessor::recursiveLoadStateMachine(), and EventProcessor::setup().

size_t append ( const std::vector< T > &  items  )  [inline]

Append a sequence of values to the list.

Parameters:
items the values to append.
Returns:
the number of values written (may be less than d.size())

Definition at line 371 of file ListLockFree.hpp.

References RTT::OS::CAS().

bool erase ( value_t  item  )  [inline]

Erase a value from the list.

Parameters:
item is to be erased from the list.
Returns:
true if found and erased.

Definition at line 406 of file ListLockFree.hpp.

References RTT::OS::CAS().

Referenced by StateMachineProcessor::clear(), EventProcessor::destroyed(), ListLockFree::erase_and_blank(), StateMachineProcessor::recursiveUnloadStateMachine(), and ProgramProcessor::unloadProgram().

void apply ( Function  func  )  [inline]

Apply a function to the elements of the whole list.

Parameters:
func The function to apply.

Definition at line 445 of file ListLockFree.hpp.

Referenced by StateMachineProcessor::finalize(), ProgramProcessor::finalize(), EventProcessor::finalize(), ProgramProcessor::getProgramList(), StateMachineProcessor::getStateMachineList(), EventProcessor::initialize(), StateMachineProcessor::step(), ProgramProcessor::step(), EventProcessor::step(), EventProcessor::~EventProcessor(), and StateMachineProcessor::~StateMachineProcessor().

void apply_and_blank ( Function  func,
value_t  blank 
) [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.

Parameters:
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.
See also:
erase_and_blank

Definition at line 470 of file ListLockFree.hpp.

bool erase_and_blank ( value_t  item,
value_t  blank 
) [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.

Warning:
It is possible that item is being processed within apply_and_blank. In that case the 'blank' operation has no effect.
Parameters:
item The item to erase from the list.
blank The 'blank' item to use to blank item from the list.
See also:
apply_and_blank

Definition at line 512 of file ListLockFree.hpp.

References ListLockFree::erase().

value_t find_if ( Function  func,
value_t  blank = value_t() 
) [inline]

Find an item in the list such that func( item ) == true.

Parameters:
blank The value to return if not found.
Returns:
The item that matches func(item) or blank if none matches.

Definition at line 539 of file ListLockFree.hpp.

Referenced by ProgramProcessor::getProgram(), ProgramProcessor::getProgramStatus(), StateMachineProcessor::getStateMachine(), StateMachineProcessor::getStateMachineStatus(), ProgramProcessor::loadProgram(), StateMachineProcessor::recursiveCheckLoadStateMachine(), StateMachineProcessor::recursiveCheckUnloadStateMachine(), StateMachineProcessor::recursiveUnloadStateMachine(), ProgramProcessor::unloadProgram(), and StateMachineProcessor::unloadStateMachine().


Member Data Documentation

const unsigned int MAX_THREADS

The maximum number of threads.

The number of threads which may concurrently access this buffer.

Definition at line 91 of file ListLockFree.hpp.


The documentation for this class was generated from the following file:
Generated on Tue Mar 25 17:41:56 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3