38 #ifndef ORO_BUFFER_LOCK_FREE_HPP 39 #define ORO_BUFFER_LOCK_FREE_HPP 41 #include "../os/oro_arch.h" 42 #include "../os/Atomic.hpp" 43 #include "../os/CAS.hpp" 45 #include "../internal/AtomicMWSRQueue.hpp" 46 #include "../internal/TsPool.hpp" 49 #ifdef ORO_PRAGMA_INTERFACE 90 BufferLockFree(
unsigned int bufsize,
const T& initial_value = T(),
bool circular =
false)
91 : bufs( bufsize ), mpool(bufsize + 1), mcircular(circular), droppedSamples(0)
147 return droppedSamples.
read();
154 droppedSamples.
inc();
162 droppedSamples.
inc();
166 if (bufs.
dequeue( mitem ) == false ) {
167 droppedSamples.
inc();
176 if (bufs.
enqueue( mitem ) == false ) {
182 droppedSamples.
inc();
190 droppedSamples.
inc();
198 }
while ( bufs.
enqueue( mitem ) == false );
204 size_type
Push(
const std::vector<T>& items)
207 int towrite = items.size();
208 size_type written = 0;
209 typename std::vector<T>::const_iterator it;
210 for( it = items.begin(); it != items.end(); ++it) {
211 if ( this->
Push( *it ) == false ) {
216 droppedSamples.
add(towrite - written);
221 bool Pop( reference_t item )
224 if (bufs.
dequeue( ipop ) == false )
232 size_type
Pop(std::vector<T>& items )
237 items.push_back( *ipop );
247 if (bufs.
dequeue( ipop ) == false )
virtual T data_sample() const
Reads back a data sample.
bool Pop(reference_t item)
Read the oldest value from the buffer.
A Lock-free buffer implementation to read and write data of type T in a FIFO way. ...
bool empty() const
Check if this buffer is empty.
bool dequeue(T &result)
Dequeue an item.
void data_sample(const T &sample)
Initializes every element of the pool with the given sample and clears the pool.
boost::call_traits< T >::reference reference_t
bool full() const
Check if this buffer is full.
size_type capacity() const
Return the maximum number of items this queue can contain.
C++ abstraction of atomic integer operations.
A Buffer is an object which is used to store (Push) and retrieve (Pop) values from.
size_type size() const
Returns the actual number of items that are stored in the buffer.
boost::call_traits< T >::param_type param_t
size_type size() const
Return the number of elements in the queue.
BufferLockFree(unsigned int bufsize, const T &initial_value=T(), bool circular=false)
Create a lock-free buffer wich can store bufsize elements.
void clear()
Clears all contents of this buffer.
bool isEmpty() const
Inspect if the Queue is empty.
BufferBase::size_type size_type
virtual void data_sample(const T &sample)
Initializes this buffer with a data sample, such that for dynamical allocated types T...
BufferInterface< T >::size_type size_type
bool CAS(volatile T *addr, const V &expected, const W &value)
Compare And Swap.
bool enqueue(const T &value)
Enqueue an item.
bool deallocate(T *Value)
size_type Push(const std::vector< T > &items)
Write a sequence of values to the buffer.
size_type Pop(std::vector< T > &items)
Read the whole buffer.
bool Push(param_t item)
Write a single value to the buffer.
int read() const
Read the current value of the integer.
size_type capacity() const
Returns the maximum number of items that can be stored in the buffer.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
BufferInterface< T >::param_t param_t
bool isFull() const
Inspect if the Queue is full.
void Release(value_t *item)
Releases the pointer.
BufferInterface< T >::reference_t reference_t
value_t * PopWithoutRelease()
Returns a pointer to the first element in the buffer.
virtual size_type dropped() const
Returns the number of dropped samples, because the buffer was full.