2 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
3 * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
6 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __ardour_butler_h__
24 #define __ardour_butler_h__
28 #include <glibmm/threads.h>
30 #include "pbd/crossthread.h"
31 #include "pbd/ringbuffer.h"
33 #include "ardour/libardour_visibility.h"
34 #include "ardour/types.h"
35 #include "ardour/session_handle.h"
42 * One of the Butler's functions is to clean up (ie delete) unused CrossThreadPools.
43 * When a thread with a CrossThreadPool terminates, its CTP is added to pool_trash.
44 * When the Butler thread wakes up, we check this trash buffer for CTPs, and if they
45 * are empty they are deleted.
48 class LIBARDOUR_API Butler : public SessionHandleRef
51 Butler (Session& session);
55 void terminate_thread();
56 void schedule_transport_work();
59 void wait_until_finished();
60 bool transport_work_requested() const;
61 void drop_references ();
63 void map_parameters ();
65 samplecnt_t audio_capture_buffer_size() const { return _audio_capture_buffer_size; }
66 samplecnt_t audio_playback_buffer_size() const { return _audio_playback_buffer_size; }
67 uint32_t midi_buffer_size() const { return _midi_buffer_size; }
69 bool flush_tracks_to_disk_after_locate (boost::shared_ptr<RouteList>, uint32_t& errors);
71 static void* _thread_work(void *arg);
84 Glib::Threads::Mutex request_lock;
85 Glib::Threads::Cond paused;
87 mutable gint should_do_transport_work;
88 samplecnt_t _audio_capture_buffer_size;
89 samplecnt_t _audio_playback_buffer_size;
90 uint32_t _midi_buffer_size;
91 PBD::RingBuffer<CrossThreadPool*> pool_trash;
94 void empty_pool_trash ();
95 void config_changed (std::string);
97 bool flush_tracks_to_disk_normal (boost::shared_ptr<RouteList>, uint32_t& errors);
100 * Add request to butler thread request queue
102 void queue_request (Request::Type r);
104 CrossThreadChannel _xthread;
108 } // namespace ARDOUR
110 #endif // __ardour_butler_h__