X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Fringbuffer.h;h=58c463ecbe5373ea344f0a536a1c17930ffea39a;hb=d0126be806c862b0a622075f2adc035b870ac662;hp=e3cec6adf1b5a42c14daed05f67e7e669a4a1250;hpb=23e7cf10191270d70357ccf0ed9294f020c7b7ab;p=ardour.git diff --git a/libs/pbd/pbd/ringbuffer.h b/libs/pbd/pbd/ringbuffer.h index e3cec6adf1..58c463ecbe 100644 --- a/libs/pbd/pbd/ringbuffer.h +++ b/libs/pbd/pbd/ringbuffer.h @@ -26,7 +26,7 @@ #include "pbd/libpbd_visibility.h" template -class /*LIBPBD_API*/ RingBuffer +class /*LIBPBD_API*/ RingBuffer { public: RingBuffer (guint sz) { @@ -39,7 +39,7 @@ class /*LIBPBD_API*/ RingBuffer buf = new T[size]; reset (); } - + virtual ~RingBuffer() { delete [] buf; } @@ -55,7 +55,7 @@ class /*LIBPBD_API*/ RingBuffer g_atomic_int_set (&write_idx, w); g_atomic_int_set (&read_idx, r); } - + guint read (T *dest, guint cnt); guint write (T const * src, guint cnt); @@ -66,25 +66,25 @@ class /*LIBPBD_API*/ RingBuffer void get_read_vector (rw_vector *); void get_write_vector (rw_vector *); - + void decrement_read_idx (guint cnt) { g_atomic_int_set (&read_idx, (g_atomic_int_get(&read_idx) - cnt) & size_mask); - } + } void increment_read_idx (guint cnt) { g_atomic_int_set (&read_idx, (g_atomic_int_get(&read_idx) + cnt) & size_mask); - } + } void increment_write_idx (guint cnt) { g_atomic_int_set (&write_idx, (g_atomic_int_get(&write_idx) + cnt) & size_mask); - } + } - guint write_space () { + guint write_space () const { guint w, r; - + w = g_atomic_int_get (&write_idx); r = g_atomic_int_get (&read_idx); - + if (w > r) { return ((r - w + size) & size_mask) - 1; } else if (w < r) { @@ -93,13 +93,13 @@ class /*LIBPBD_API*/ RingBuffer return size - 1; } } - - guint read_space () { + + guint read_space () const { guint w, r; - + w = g_atomic_int_get (&write_idx); r = g_atomic_int_get (&read_idx); - + if (w > r) { return w - r; } else { @@ -120,7 +120,7 @@ class /*LIBPBD_API*/ RingBuffer guint size_mask; }; -template /*LIBPBD_API*/ guint +template /*LIBPBD_API*/ guint RingBuffer::read (T *dest, guint cnt) { guint free_cnt; @@ -136,7 +136,7 @@ RingBuffer::read (T *dest, guint cnt) } to_read = cnt > free_cnt ? free_cnt : cnt; - + cnt2 = priv_read_idx + to_read; if (cnt2 > size) { @@ -146,7 +146,7 @@ RingBuffer::read (T *dest, guint cnt) n1 = to_read; n2 = 0; } - + memcpy (dest, &buf[priv_read_idx], n1 * sizeof (T)); priv_read_idx = (priv_read_idx + n1) & size_mask; @@ -176,7 +176,7 @@ RingBuffer::write (T const *src, guint cnt) } to_write = cnt > free_cnt ? free_cnt : cnt; - + cnt2 = priv_write_idx + to_write; if (cnt2 > size) { @@ -206,10 +206,10 @@ RingBuffer::get_read_vector (typename RingBuffer::rw_vector *vec) guint free_cnt; guint cnt2; guint w, r; - + w = g_atomic_int_get (&write_idx); r = g_atomic_int_get (&read_idx); - + if (w > r) { free_cnt = w - r; } else { @@ -220,7 +220,7 @@ RingBuffer::get_read_vector (typename RingBuffer::rw_vector *vec) if (cnt2 > size) { /* Two part vector: the rest of the buffer after the - current write ptr, plus some from the start of + current write ptr, plus some from the start of the buffer. */ @@ -230,9 +230,9 @@ RingBuffer::get_read_vector (typename RingBuffer::rw_vector *vec) vec->len[1] = cnt2 & size_mask; } else { - + /* Single part vector: just the rest of the buffer */ - + vec->buf[0] = &buf[r]; vec->len[0] = free_cnt; vec->buf[1] = 0; @@ -247,10 +247,10 @@ RingBuffer::get_write_vector (typename RingBuffer::rw_vector *vec) guint free_cnt; guint cnt2; guint w, r; - + w = g_atomic_int_get (&write_idx); r = g_atomic_int_get (&read_idx); - + if (w > r) { free_cnt = ((r - w + size) & size_mask) - 1; } else if (w < r) { @@ -258,13 +258,13 @@ RingBuffer::get_write_vector (typename RingBuffer::rw_vector *vec) } else { free_cnt = size - 1; } - + cnt2 = w + free_cnt; if (cnt2 > size) { - + /* Two part vector: the rest of the buffer after the - current write ptr, plus some from the start of + current write ptr, plus some from the start of the buffer. */