35 std::atomic<int> state { STATE_EMPTY };
36 std::vector<unsigned char> data;
41 write_simple (
const void *ptr,
size_t size)
43 size_t new_wpos = wpos + size;
44 if (new_wpos <= data.size())
45 memcpy (&data[wpos], ptr, size);
50 read_simple (
void *ptr,
size_t size)
54 memcpy (ptr, &data[rpos], size);
66 if (state.load() == STATE_EMPTY)
76 if (wpos <= data.size())
78 state.store (STATE_DATA_VALID);
82 state.store (STATE_NEED_RESIZE);
88 if (state.load() == STATE_NEED_RESIZE)
90 data.resize (data.size() * 2);
91 state.store (STATE_EMPTY);
97 if (state.load() == STATE_DATA_VALID)
107 state.store (STATE_EMPTY);
112 write_simple (&i,
sizeof (i));
115 write_float (
float f)
117 write_simple (&f,
sizeof (f));
119 template<
class T>
void
120 write_seq (
const T* items,
size_t length)
123 write_simple (items, length *
sizeof (T));
134 read_simple (&i,
sizeof (i));
141 read_simple (&f,
sizeof (f));
144 template<
class T> std::vector<T>
147 int seq_len = read_int();
148 std::vector<T> result (seq_len);
149 read_simple (result.data(), seq_len * sizeof (T));
Definition: smnotifybuffer.hh:29