X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fbuffer_manager.cc;h=c221837af88ddef013ca597ecf1ec8a272f348e0;hb=5b4c3aa226dc95f33dc3ffae6669a24f5e8b8fe0;hp=3436dac72d203b93a3876ebd159f4fb9178e9ff1;hpb=3ea10b38bbb4b471178793f68fbd3a0ee74449f6;p=ardour.git diff --git a/libs/ardour/buffer_manager.cc b/libs/ardour/buffer_manager.cc index 3436dac72d..c221837af8 100644 --- a/libs/ardour/buffer_manager.cc +++ b/libs/ardour/buffer_manager.cc @@ -18,6 +18,9 @@ */ #include + +#include "pbd/compose.h" + #include "ardour/buffer_manager.h" #include "ardour/thread_buffers.h" @@ -25,38 +28,38 @@ using namespace ARDOUR; using namespace PBD; RingBufferNPT* BufferManager::thread_buffers = 0; +std::list* BufferManager::thread_buffers_list = 0; +Glib::Threads::Mutex BufferManager::rb_mutex; + +using std::cerr; +using std::endl; 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); } + // cerr << "Initialized thread buffers, readable count now " << thread_buffers->read_space() << endl; - 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::Threads::Mutex::Lock em (rb_mutex); ThreadBuffers* tbp; if (thread_buffers->read (&tbp, 1) == 1) { + // cerr << "Got thread buffers, readable count now " << thread_buffers->read_space() << endl; return tbp; } @@ -66,17 +69,17 @@ BufferManager::get_thread_buffers () void BufferManager::put_thread_buffers (ThreadBuffers* tbp) { + Glib::Threads::Mutex::Lock em (rb_mutex); thread_buffers->write (&tbp, 1); + // cerr << "Put back thread buffers, readable count now " << thread_buffers->read_space() << endl; } void -BufferManager::ensure_buffers (ChanCount howmany) +BufferManager::ensure_buffers (ChanCount howmany, size_t custom) { /* 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, custom); + } }