39 #ifndef ORO_CORELIB_ATOMIC_QUEUE_HPP 40 #define ORO_CORELIB_ATOMIC_QUEUE_HPP 42 #include "../os/CAS.hpp" 74 typedef volatile C* CachePtrType;
75 typedef C*
volatile CacheObjType;
82 unsigned short _index[2];
95 volatile SIndexes _indxes;
104 CachePtrType recover_r()
const 111 start._value = _indxes._value;
112 unsigned short r = start._index[1];
119 while( r != start._index[1]) {
131 CachePtrType propose_w()
133 SIndexes oldval, newval;
135 oldval._value = _indxes._value;
136 newval._value = oldval._value;
138 if ( (newval._index[0] == newval._index[1] - 1) || (newval._index[0] == newval._index[1] + _size - 1) )
145 if ( newval._index[0] == _size )
146 newval._index[0] = 0;
148 }
while ( !
os::CAS( &_indxes._value, oldval._value, newval._value) );
151 return &_buf[ oldval._index[0] ];
157 CachePtrType propose_r()
159 SIndexes oldval, newval;
161 oldval._value = _indxes._value;
162 newval._value = oldval._value;
164 if ( newval._index[0] == newval._index[1] )
172 if ( newval._index[1] == _size )
173 newval._index[1] = 0;
175 }
while ( !
os::CAS( &_indxes._value, oldval._value, newval._value) );
178 return &_buf[oldval._index[1] ];
212 val._value = _indxes._value;
213 return val._index[0] == val._index[1] - 1 || val._index[0] == val._index[1] + _size - 1;
224 val._value = _indxes._value;
225 return val._index[0] == val._index[1] && recover_r() == 0;
244 while (c != _size ) {
269 }
while( !
os::CAS(loc, null, value));
288 }
while( result == 0 || !
os::CAS(loc, result, null) );
298 return _buf[_indxes._index[1] ];
306 for(
int i = 0 ; i != _size; ++i) {
size_type size() const
Return the exact number of elements in the queue.
void clear()
Clear all contents of the Queue and thus make it empty.
Create an atomic, non-blocking single ended queue (FIFO) for storing a pointer to T...
bool CAS(volatile T *addr, const V &expected, const W &value)
Compare And Swap.
bool enqueue(const T &value)
Enqueue an item.
bool isEmpty() const
Inspect if the Queue is empty.
bool dequeue(T &result)
Dequeue an item.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
const T front() const
Return the next to be read value.
size_type capacity() const
Return the maximum number of items this queue can contain.
AtomicQueue(unsigned int size)
Create an AtomicQueue with queue size size.
bool isFull() const
Inspect if the Queue is full.