55 void set (
size_t r,
size_t w) {
61 size_t read (T *dest,
size_t cnt);
62 size_t write (
const T *src,
size_t cnt);
128 template<
class T>
size_t
135 size_t priv_read_ptr;
137 priv_read_ptr = read_ptr.load ();
139 if ((free_cnt = read_space ()) == 0) {
143 to_read = cnt > free_cnt ? free_cnt : cnt;
145 cnt2 = priv_read_ptr + to_read;
148 n1 = size - priv_read_ptr;
155 memcpy (dest, &buf[priv_read_ptr], n1 *
sizeof (T));
156 priv_read_ptr = (priv_read_ptr + n1) % size;
159 memcpy (dest+n1, buf, n2 *
sizeof (T));
163 read_ptr.store (priv_read_ptr);
167 template<
class T>
size_t
174 size_t priv_write_ptr;
176 priv_write_ptr = write_ptr.load ();
178 if ((free_cnt = write_space ()) == 0) {
182 to_write = cnt > free_cnt ? free_cnt : cnt;
184 cnt2 = priv_write_ptr + to_write;
187 n1 = size - priv_write_ptr;
194 memcpy (&buf[priv_write_ptr], src, n1 *
sizeof (T));
195 priv_write_ptr = (priv_write_ptr + n1) % size;
198 memcpy (buf, src+n1, n2 *
sizeof (T));
202 write_ptr.store (priv_write_ptr);
206 template<
class T>
size_t
209 return write (&src, 1);
212 template<
class T>
void
219 w = write_ptr.load ();
220 r = read_ptr.load ();
225 free_cnt = (w - r + size) % size;
236 vec->
buf[0] = &buf[r];
237 vec->
len[0] = size - r;
239 vec->
len[1] = cnt2 % size;
245 vec->
buf[0] = &buf[r];
246 vec->
len[0] = free_cnt;
252 template<
class T>
void
259 w = write_ptr.load ();
260 r = read_ptr.load ();
263 free_cnt = ((r - w + size) % size) - 1;
265 free_cnt = (r - w) - 1;
279 vec->
buf[0] = &buf[w];
280 vec->
len[0] = size - w;
282 vec->
len[1] = cnt2 % size;
284 vec->
buf[0] = &buf[w];
285 vec->
len[0] = free_cnt;
std::atomic< int > write_ptr
std::atomic< int > read_ptr
size_t write(const T *src, size_t cnt)
void increment_read_ptr(size_t cnt)
void get_write_vector(rw_vector *)
size_t get_read_ptr() const
void increment_write_ptr(size_t cnt)
size_t write_one(const T src)
size_t read(T *dest, size_t cnt)
void decrement_read_ptr(size_t cnt)
RingBufferNPT(RingBufferNPT const &)
void get_read_vector(rw_vector *)
void set(size_t r, size_t w)
size_t get_write_ptr() const