Move a few declarations to first use.
[ardour.git] / libs / ardour / buffer_manager.cc
index 3436dac72d203b93a3876ebd159f4fb9178e9ff1..5a2d941eafc89ec4b6eca62f9a28f62094924444 100644 (file)
 */
 
 #include <iostream>
+
+#include "pbd/compose.h"
+
 #include "ardour/buffer_manager.h"
+#include "ardour/debug.h"
 #include "ardour/thread_buffers.h"
 
 using namespace ARDOUR;
 using namespace PBD;
 
 RingBufferNPT<ThreadBuffers*>* BufferManager::thread_buffers = 0;
+std::list<ThreadBuffers*>* BufferManager::thread_buffers_list = 0;
+Glib::StaticMutex BufferManager::rb_mutex = GLIBMM_STATIC_MUTEX_INIT;
 
 void
 BufferManager::init (uint32_t size)
 {
         thread_buffers = new ThreadBufferFIFO (size+1); // must be one larger than requested
+       thread_buffers_list = new ThreadBufferList;
 
-        /* and populate with actual ThreadBuffers 
+        /* and populate with actual ThreadBuffers
          */
 
-        std::cerr << "BM: initial read space: " << thread_buffers->read_space() << std::endl;
-        
-        for (uint32_t n = 0; n < size; ++n) {        
+        for (uint32_t n = 0; n < size; ++n) {
                 ThreadBuffers* ts = new ThreadBuffers;
                 thread_buffers->write (&ts, 1);
-                std::cerr << "BM: added one, read =  " << thread_buffers->read_space() 
-                          << " write = " << thread_buffers->write_space() 
-                          << std::endl;
+               thread_buffers_list->push_back (ts);
         }
-
-        std::cerr << "BM: final, read =  " << thread_buffers->read_space() 
-                  << " write = " << thread_buffers->write_space() 
-                  << std::endl;
-
-        std::cerr << "BUFFER MANAGER INITIALIZED WITH " << size << " BUFFERs\n";
 }
 
 ThreadBuffers*
 BufferManager::get_thread_buffers ()
 {
+       Glib::Mutex::Lock em (rb_mutex);
         ThreadBuffers* tbp;
 
         if (thread_buffers->read (&tbp, 1) == 1) {
@@ -66,6 +64,7 @@ BufferManager::get_thread_buffers ()
 void
 BufferManager::put_thread_buffers (ThreadBuffers* tbp)
 {
+       Glib::Mutex::Lock em (rb_mutex);
         thread_buffers->write (&tbp, 1);
 }
 
@@ -74,9 +73,7 @@ BufferManager::ensure_buffers (ChanCount howmany)
 {
         /* this is protected by the audioengine's process lock: we do not  */
 
-        std::cerr << "BufMgr: ensure " << thread_buffers->bufsize() - 1 << " buffers match " << howmany << std::endl;
-
-        for (uint32_t n = 0; n < thread_buffers->bufsize() - 1; ++n) {
-                thread_buffers->buffer()[n]->ensure_buffers (howmany);
-        }
+       for (ThreadBufferList::iterator i = thread_buffers_list->begin(); i != thread_buffers_list->end(); ++i) {
+               (*i)->ensure_buffers (howmany);
+       }
 }