diff options
Diffstat (limited to 'gr-audio-osx/src/circular_buffer.h')
-rw-r--r-- | gr-audio-osx/src/circular_buffer.h | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/gr-audio-osx/src/circular_buffer.h b/gr-audio-osx/src/circular_buffer.h index fa451d607..996b1b74b 100644 --- a/gr-audio-osx/src/circular_buffer.h +++ b/gr-audio-osx/src/circular_buffer.h @@ -26,7 +26,9 @@ #include "mld_threads.h" #include <stdexcept> +#ifndef DO_DEBUG #define DO_DEBUG 0 +#endif #if DO_DEBUG #define DEBUG(X) do{X} while(0); @@ -41,8 +43,8 @@ private: T* d_buffer; // the following are in Items (type T) - UInt32 d_bufLen_I, d_readNdx_I, d_writeNdx_I; - UInt32 d_n_avail_write_I, d_n_avail_read_I; + size_t d_bufLen_I, d_readNdx_I, d_writeNdx_I; + size_t d_n_avail_write_I, d_n_avail_read_I; // stuff to control access to class internals mld_mutex_ptr d_internal; @@ -67,7 +69,7 @@ private: }; public: - circular_buffer (UInt32 bufLen_I, + circular_buffer (size_t bufLen_I, bool doWriteBlock = true, bool doFullRead = false) { if (bufLen_I == 0) throw std::runtime_error ("circular_buffer(): " @@ -82,7 +84,7 @@ public: DEBUG (fprintf (stderr, "c_b(): buf len (items) = %ld, " "doWriteBlock = %s, doFullRead = %s\n", d_bufLen_I, (d_doWriteBlock ? "true" : "false"), - (d_doFullRead ? "true" : "false"))); + (d_doFullRead ? "true" : "false"));); }; ~circular_buffer () { @@ -90,21 +92,21 @@ public: delete [] d_buffer; }; - inline UInt32 n_avail_write_items () { + inline size_t n_avail_write_items () { d_internal->lock (); - UInt32 retVal = d_n_avail_write_I; + size_t retVal = d_n_avail_write_I; d_internal->unlock (); return (retVal); }; - inline UInt32 n_avail_read_items () { + inline size_t n_avail_read_items () { d_internal->lock (); - UInt32 retVal = d_n_avail_read_I; + size_t retVal = d_n_avail_read_I; d_internal->unlock (); return (retVal); }; - inline UInt32 buffer_length_items () {return (d_bufLen_I);}; + inline size_t buffer_length_items () {return (d_bufLen_I);}; inline bool do_write_block () {return (d_doWriteBlock);}; inline bool do_full_read () {return (d_doFullRead);}; @@ -147,10 +149,10 @@ public: * buffer length is larger than the instantiated buffer length */ - int enqueue (T* buf, UInt32 bufLen_I) { + int enqueue (T* buf, size_t bufLen_I) { DEBUG (fprintf (stderr, "enqueue: buf = %X, bufLen = %ld, #av_wr = %ld, " "#av_rd = %ld.\n", (unsigned int)buf, bufLen_I, - d_n_avail_write_I, d_n_avail_read_I)); + d_n_avail_write_I, d_n_avail_read_I);); if (bufLen_I > d_bufLen_I) { fprintf (stderr, "cannot add buffer longer (%ld" ") than instantiated length (%ld" @@ -173,25 +175,25 @@ public: if (bufLen_I > d_n_avail_write_I) { if (d_doWriteBlock) { while (bufLen_I > d_n_avail_write_I) { - DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n")); + DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n");); // wait will automatically unlock() the internal mutex d_writeBlock->wait (); // and lock() it here. if (d_doAbort) { d_internal->unlock (); - DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n")); + DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n");); return (2); } - DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n")); + DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n");); } } else { d_n_avail_read_I = d_bufLen_I - bufLen_I; d_n_avail_write_I = bufLen_I; - DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n")); + DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n");); retval = -1; } } - UInt32 n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0; + size_t n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0; if (n_now_I > bufLen_I) n_now_I = bufLen_I; else if (n_now_I < bufLen_I) @@ -230,17 +232,17 @@ public: * buffer length is larger than the instantiated buffer length */ - int dequeue (T* buf, UInt32* bufLen_I) { + int dequeue (T* buf, size_t* bufLen_I) { DEBUG (fprintf (stderr, "dequeue: buf = %X, *bufLen = %ld, #av_wr = %ld, " "#av_rd = %ld.\n", (unsigned int)buf, *bufLen_I, - d_n_avail_write_I, d_n_avail_read_I)); + d_n_avail_write_I, d_n_avail_read_I);); if (!bufLen_I) throw std::runtime_error ("circular_buffer::dequeue(): " "input bufLen pointer is NULL.\n"); if (!buf) throw std::runtime_error ("circular_buffer::dequeue(): " "input buffer pointer is NULL.\n"); - UInt32 l_bufLen_I = *bufLen_I; + size_t l_bufLen_I = *bufLen_I; if (l_bufLen_I == 0) return (0); if (l_bufLen_I > d_bufLen_I) { @@ -257,34 +259,34 @@ public: } if (d_doFullRead) { while (d_n_avail_read_I < l_bufLen_I) { - DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n")); + DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n");); // wait will automatically unlock() the internal mutex d_readBlock->wait (); // and lock() it here. if (d_doAbort) { d_internal->unlock (); - DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n")); + DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n");); return (2); } - DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n")); + DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n");); } } else { while (d_n_avail_read_I == 0) { - DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n")); + DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n");); // wait will automatically unlock() the internal mutex d_readBlock->wait (); // and lock() it here. if (d_doAbort) { d_internal->unlock (); - DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n")); + DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n");); return (2); } - DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n")); + DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n");); } } if (l_bufLen_I > d_n_avail_read_I) l_bufLen_I = d_n_avail_read_I; - UInt32 n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0; + size_t n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0; if (n_now_I > l_bufLen_I) n_now_I = l_bufLen_I; else if (n_now_I < l_bufLen_I) |