Merge branch 'master' into cairocanvas
[ardour.git] / libs / pbd / pbd / ringbuffer.h
index f50593bfb7f478b50259f09f40a16b90d7e24c1d..f14fa7185184356d154f40da1a134446d0200bb0 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef ringbuffer_h
 #define ringbuffer_h
 
+#include <cstring>
 #include <glib.h>
 
 template<class T>
@@ -29,14 +30,13 @@ class RingBuffer
        RingBuffer (guint sz) {
 //     size = ffs(sz); /* find first [bit] set is a single inlined assembly instruction. But it looks like the API rounds up so... */
        guint power_of_two;
-       for (power_of_two = 1; 1U<<power_of_two < sz; power_of_two++);
-               size = 1<<power_of_two;
-               size_mask = size;
-               size_mask -= 1;
-               buf = new T[size];
-               reset ();
-
-       };
+       for (power_of_two = 1; 1U<<power_of_two < sz; power_of_two++) {}
+       size = 1<<power_of_two;
+       size_mask = size;
+       size_mask -= 1;
+       buf = new T[size];
+       reset ();
+       }
        
        virtual ~RingBuffer() {
                delete [] buf;
@@ -55,7 +55,7 @@ class RingBuffer
        }
        
        guint read  (T *dest, guint cnt);
-       guint  write (T *src, guint cnt);
+       guint write (T const * src,  guint cnt);
 
        struct rw_vector {
            T *buf[2];
@@ -113,8 +113,8 @@ class RingBuffer
   protected:
        T *buf;
        guint size;
-       mutable guint write_idx;
-       mutable guint read_idx;
+       mutable gint write_idx;
+       mutable gint read_idx;
        guint size_mask;
 };
 
@@ -158,7 +158,7 @@ RingBuffer<T>::read (T *dest, guint cnt)
 }
 
 template<class T> guint
-RingBuffer<T>::write (T *src, guint cnt)
+RingBuffer<T>::write (T const *src, guint cnt)
 
 {
         guint free_cnt;