24 |
#ifndef RINGBUFFER_H |
#ifndef RINGBUFFER_H |
25 |
#define RINGBUFFER_H |
#define RINGBUFFER_H |
26 |
|
|
27 |
#define DEFAULT_WRAP_ELEMENTS 1024 |
#define DEFAULT_WRAP_ELEMENTS 0 |
28 |
|
|
29 |
#include <string.h> |
#include <string.h> |
30 |
|
|
94 |
inline void fill_write_space_with_null() { |
inline void fill_write_space_with_null() { |
95 |
int w = atomic_read(&write_ptr), |
int w = atomic_read(&write_ptr), |
96 |
r = atomic_read(&read_ptr); |
r = atomic_read(&read_ptr); |
97 |
memset(get_write_ptr(), 0, write_space_to_end()); |
memset(get_write_ptr(), 0, sizeof(T)*write_space_to_end()); |
98 |
if (r && w >= r) { |
if (r && w >= r) { |
99 |
memset(get_buffer_begin(), 0, r - 1); |
memset(get_buffer_begin(), 0, sizeof(T)*(r - 1)); |
100 |
} |
} |
101 |
|
|
102 |
// set the wrap space elements to null |
// set the wrap space elements to null |
103 |
if (wrap_elements) memset(&buf[size], 0, wrap_elements); |
if (wrap_elements) memset(&buf[size], 0, sizeof(T)*wrap_elements); |
104 |
} |
} |
105 |
|
|
106 |
__inline int read (T *dest, int cnt); |
__inline int read (T *dest, int cnt); |
301 |
*/ |
*/ |
302 |
inline void operator--() { |
inline void operator--() { |
303 |
if (read_ptr == atomic_read(&pBuf->read_ptr)) return; //TODO: or should we react oh this case (e.g. force segfault), as this is a very odd case? |
if (read_ptr == atomic_read(&pBuf->read_ptr)) return; //TODO: or should we react oh this case (e.g. force segfault), as this is a very odd case? |
304 |
--read_ptr & pBuf->size_mask; |
read_ptr = (read_ptr-1) & pBuf->size_mask; |
305 |
} |
} |
306 |
|
|
307 |
/** |
/** |