18 #ifndef RAUL_SRMW_QUEUE_HPP
19 #define RAUL_SRMW_QUEUE_HPP
25 #include <boost/utility.hpp>
27 #include "raul/AtomicInt.hpp"
63 inline size_t capacity()
const {
return _size-1; }
68 inline bool full()
const;
69 inline bool push(
const T& obj);
74 inline bool empty()
const;
75 inline T&
front()
const;
99 , _objects((T*)calloc(_size, sizeof(T)))
102 assert(log2(size) - (
int)log2(size) == 0);
104 assert(_size-1 == (
unsigned)_write_space.get());
106 for (
unsigned i=0; i < _size; ++i) {
107 assert(_valid[i].get() == 0);
112 template <
typename T>
113 SRMWQueue<T>::~SRMWQueue()
123 template <
typename T>
127 return (_write_space.get() <= 0);
138 template <
typename T>
142 const int old_write_space = _write_space.exchange_and_add(-1);
143 const bool already_full = ( old_write_space <= 0 );
161 const unsigned write_index = (unsigned)_back.exchange_and_add(1) % _size;
163 assert(_valid[write_index] == 0);
164 _objects[write_index] = elem;
165 ++(_valid[write_index]);
177 template <
typename T>
181 return (_valid[_front].get() == 0);
190 template <
typename T>
194 return _objects[_front];
205 template <
typename T>
209 assert(_valid[_front] == 1);
212 _front = (_front + 1) % (_size);
214 if (_write_space.get() < 0)
223 #endif // RAUL_SRMW_QUEUE_HPP