39 #ifndef ORO_CORELIB_ATOMIC_MWMR_QUEUE_HPP 40 #define ORO_CORELIB_ATOMIC_MWMR_QUEUE_HPP 43 #include "../os/CAS.hpp" 75 typedef volatile C* CachePtrType;
76 typedef C*
volatile CacheObjType;
83 unsigned short _index[2];
96 volatile SIndexes _indxes;
105 CachePtrType recover_r()
const 112 start._value = _indxes._value;
113 unsigned short r = start._index[1];
120 while( r != start._index[1]) {
132 CachePtrType propose_w()
134 SIndexes oldval, newval;
136 oldval._value = _indxes._value;
137 newval._value = oldval._value;
139 if ( (newval._index[0] == newval._index[1] - 1) || (newval._index[0] == newval._index[1] + _size - 1) )
146 if ( newval._index[0] == _size )
147 newval._index[0] = 0;
149 }
while ( !
os::CAS( &_indxes._value, oldval._value, newval._value) );
152 return &_buf[ oldval._index[0] ];
158 CachePtrType propose_r()
160 SIndexes oldval, newval;
162 oldval._value = _indxes._value;
163 newval._value = oldval._value;
165 if ( newval._index[0] == newval._index[1] )
173 if ( newval._index[1] == _size )
174 newval._index[1] = 0;
176 }
while ( !
os::CAS( &_indxes._value, oldval._value, newval._value) );
179 return &_buf[oldval._index[1] ];
213 val._value = _indxes._value;
214 return val._index[0] == val._index[1] - 1 || val._index[0] == val._index[1] + _size - 1;
225 val._value = _indxes._value;
226 return val._index[0] == val._index[1] && recover_r() == 0;
245 while (c != _size ) {
270 }
while( !
os::CAS(loc, null, value));
289 }
while( result == 0 || !
os::CAS(loc, result, null) );
299 return _buf[_indxes._index[1] ];
307 for(
int i = 0 ; i != _size; ++i) {
size_type size() const
Return the exact number of elements in the queue.
bool dequeue(T &result)
Dequeue an item.
An atomic, non-blocking single ended queue (FIFO) for storing a pointer to T.
const T front() const
Return the next to be read value.
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.
AtomicMWMRQueue(unsigned int size)
Create an AtomicQueue with queue size size.
void clear()
Clear all contents of the Queue and thus make it empty.
bool isEmpty() const
Inspect if the Queue is empty.
bool enqueue(const T &value)
Enqueue an item.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
AtomicQueue< T >::size_type size_type
bool isFull() const
Inspect if the Queue is full.
size_type capacity() const
Return the maximum number of items this queue can contain.