2 * Copyright (C) 2010-2012 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2011-2012 David Robillard <d@drobilla.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "pbd/compose.h"
25 #include "ardour/buffer_manager.h"
26 #include "ardour/thread_buffers.h"
28 using namespace ARDOUR;
31 RingBufferNPT<ThreadBuffers*>* BufferManager::thread_buffers = 0;
32 std::list<ThreadBuffers*>* BufferManager::thread_buffers_list = 0;
33 Glib::Threads::Mutex BufferManager::rb_mutex;
39 BufferManager::init (uint32_t size)
41 thread_buffers = new ThreadBufferFIFO (size+1); // must be one larger than requested
42 thread_buffers_list = new ThreadBufferList;
44 /* and populate with actual ThreadBuffers
47 for (uint32_t n = 0; n < size; ++n) {
48 ThreadBuffers* ts = new ThreadBuffers;
49 thread_buffers->write (&ts, 1);
50 thread_buffers_list->push_back (ts);
52 // cerr << "Initialized thread buffers, readable count now " << thread_buffers->read_space() << endl;
57 BufferManager::get_thread_buffers ()
59 Glib::Threads::Mutex::Lock em (rb_mutex);
62 if (thread_buffers->read (&tbp, 1) == 1) {
63 // cerr << "Got thread buffers, readable count now " << thread_buffers->read_space() << endl;
71 BufferManager::put_thread_buffers (ThreadBuffers* tbp)
73 Glib::Threads::Mutex::Lock em (rb_mutex);
74 thread_buffers->write (&tbp, 1);
75 // cerr << "Put back thread buffers, readable count now " << thread_buffers->read_space() << endl;
79 BufferManager::ensure_buffers (ChanCount howmany, size_t custom)
81 /* this is protected by the audioengine's process lock: we do not */
83 for (ThreadBufferList::iterator i = thread_buffers_list->begin(); i != thread_buffers_list->end(); ++i) {
84 (*i)->ensure_buffers (howmany, custom);