39 #ifndef ORO_CORELIB_ATOMIC_MWSR_QUEUE_HPP 40 #define ORO_CORELIB_ATOMIC_MWSR_QUEUE_HPP 42 #include "../os/CAS.hpp" 64 typedef volatile C* CachePtrType;
65 typedef C*
volatile CacheObjType;
79 unsigned short _index[2];
92 volatile SIndexes _indxes;
98 CachePtrType advance_w()
100 SIndexes oldval, newval;
103 oldval._value = _indxes._value;
104 newval._value = oldval._value;
106 if ((newval._index[0] == newval._index[1] - 1) || (newval._index[0] == newval._index[1] + _size - 1))
111 if (newval._index[0] >= _size)
112 newval._index[0] = 0;
114 }
while (!
os::CAS(&_indxes._value, oldval._value, newval._value));
121 return &_buf[oldval._index[0]];
128 bool advance_r(T& result)
130 SIndexes oldval, newval;
132 oldval._value = _indxes._value;
133 result = _buf[oldval._index[1]];
138 _buf[oldval._index[1]] = 0;
145 oldval._value = _indxes._value;
146 newval._value = oldval._value;
148 if (newval._index[1] >= _size)
149 newval._index[1] = 0;
153 }
while (!
os::CAS(&_indxes._value, oldval._value, newval._value));
189 val._value = _indxes._value;
190 return val._index[0] == val._index[1] - 1 || val._index[0] == val._index[1] + _size - 1;
201 val._value = _indxes._value;
202 return val._index[0] == val._index[1];
219 val._value = _indxes._value;
220 int c = (val._index[0] - val._index[1]);
221 return c >= 0 ? c : c + _size;
233 CachePtrType loc = advance_w();
250 if (advance_r(tmpresult) ) {
262 return _buf[_indxes._index[1]];
270 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.
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...