39 #ifndef ORO_CORELIB_ATOMIC_MWSR_QUEUE_HPP 40 #define ORO_CORELIB_ATOMIC_MWSR_QUEUE_HPP 43 #include "../os/CAS.hpp" 65 typedef volatile C* CachePtrType;
66 typedef C*
volatile CacheObjType;
80 unsigned short _index[2];
93 volatile SIndexes _indxes;
99 CachePtrType advance_w()
101 SIndexes oldval, newval;
104 oldval._value = _indxes._value;
105 newval._value = oldval._value;
107 if ((newval._index[0] == newval._index[1] - 1) || (newval._index[0] == newval._index[1] + _size - 1))
112 if (newval._index[0] >= _size)
113 newval._index[0] = 0;
115 }
while (!
os::CAS(&_indxes._value, oldval._value, newval._value));
122 return &_buf[oldval._index[0]];
129 bool advance_r(T& result)
131 SIndexes oldval, newval;
133 oldval._value = _indxes._value;
134 result = _buf[oldval._index[1]];
139 _buf[oldval._index[1]] = 0;
146 oldval._value = _indxes._value;
147 newval._value = oldval._value;
149 if (newval._index[1] >= _size)
150 newval._index[1] = 0;
154 }
while (!
os::CAS(&_indxes._value, oldval._value, newval._value));
191 val._value = _indxes._value;
192 return val._index[0] == val._index[1] - 1 || val._index[0] == val._index[1] + _size - 1;
203 val._value = _indxes._value;
204 return val._index[0] == val._index[1];
221 val._value = _indxes._value;
222 int c = (val._index[0] - val._index[1]);
223 return c >= 0 ? c : c + _size;
235 CachePtrType loc = advance_w();
252 if (advance_r(tmpresult) ) {
264 return _buf[_indxes._index[1]];
272 for (
int i = 0; i != _size; ++i)
AtomicMWSRQueue(unsigned int size)
Create an AtomicMWSRQueue with queue size size.
const T front() const
Return the next to be read value.
bool dequeue(T &result)
Dequeue an item.
size_type capacity() const
Return the maximum number of items this queue can contain.
An atomic, non-blocking single ended queue (FIFO) for storing a pointer to T.
size_type size() const
Return the number of elements in the queue.
bool isEmpty() const
Inspect if the Queue is empty.
bool CAS(volatile T *addr, const V &expected, const W &value)
Compare And Swap.
bool enqueue(const T &value)
Enqueue an item.
void clear()
Clear all contents of the Queue and thus make it empty.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
bool isFull() const
Inspect if the Queue is full.
Create an atomic, non-blocking Multi-Writer Single-Reader FIFO for storing a pointer T by value...
AtomicQueue< T >::size_type size_type