diff options
author | David Robillard <d@drobilla.net> | 2009-10-23 23:23:00 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-10-23 23:23:00 +0000 |
commit | d56817e7856040adf3db6bda812dfaef7d493c80 (patch) | |
tree | cd7fcd88f4686bd48e9a4465eaaac3d96f3f68c9 | |
parent | 002ff65d0f75431bb42cc29836d6237ba1b7d704 (diff) |
Split butler into separate object (partially, just data so far...)
git-svn-id: svn://localhost/ardour2/branches/3.0@5900 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/ardour/ardour/butler.h | 43 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 12 | ||||
-rw-r--r-- | libs/ardour/butler.cc | 34 | ||||
-rw-r--r-- | libs/ardour/session.cc | 5 | ||||
-rw-r--r-- | libs/ardour/session_butler.cc | 60 | ||||
-rw-r--r-- | libs/ardour/session_export.cc | 5 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 2 | ||||
-rw-r--r-- | libs/ardour/session_transport.cc | 25 | ||||
-rw-r--r-- | libs/ardour/wscript | 1 |
9 files changed, 134 insertions, 53 deletions
diff --git a/libs/ardour/ardour/butler.h b/libs/ardour/ardour/butler.h new file mode 100644 index 0000000000..524651ba28 --- /dev/null +++ b/libs/ardour/ardour/butler.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2000-2009 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __ardour_butler_h__ +#define __ardour_butler_h__ + +#include <glibmm/thread.h> +#include "ardour/types.h" + +namespace ARDOUR { + +class Butler { +public: + Butler(); + ~Butler(); + + pthread_t thread; + Glib::Mutex request_lock; + Glib::Cond paused; + bool should_run; + mutable gint should_do_transport_work; + int request_pipe[2]; +}; + +} // namespace ARDOUR + +#endif // __ardour_butler_h__ diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 0e543462ae..aa15f07e8d 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -114,6 +114,7 @@ class Slave; class Source; class TempoMap; class VSTPlugin; +class Butler; class Session : public PBD::StatefulDestructible, public boost::noncopyable { @@ -1187,16 +1188,9 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable bool pending_abort; bool pending_auto_loop; - pthread_t butler_thread; - Glib::Mutex butler_request_lock; - Glib::Cond butler_paused; - bool butler_should_run; - mutable gint butler_should_do_transport_work; - int butler_request_pipe[2]; + Butler* butler; - inline bool transport_work_requested() const { - return g_atomic_int_get(&butler_should_do_transport_work); - } + bool transport_work_requested() const; struct ButlerRequest { enum Type { diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc new file mode 100644 index 0000000000..33811ca387 --- /dev/null +++ b/libs/ardour/butler.cc @@ -0,0 +1,34 @@ +/* + Copyright (C) 1999-2009 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "ardour/butler.h" + +namespace ARDOUR { + +Butler::Butler() + : thread(0) +{ + g_atomic_int_set(&should_do_transport_work, 0); +} + +Butler::~Butler() +{ +} + +} // namespace ARDOUR diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index e4de8ea6c4..a42d764c9e 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -56,6 +56,7 @@ #include "ardour/auditioner.h" #include "ardour/buffer_set.h" #include "ardour/bundle.h" +#include "ardour/butler.h" #include "ardour/click.h" #include "ardour/configuration.h" #include "ardour/crossfade.h" @@ -129,6 +130,7 @@ Session::Session (AudioEngine &eng, _session_dir (new SessionDirectory(fullpath)), pending_events (2048), state_tree (0), + butler (new Butler ()), post_transport_work((PostTransportWork)0), _send_smpte_update (false), midi_thread (pthread_t (0)), @@ -214,6 +216,7 @@ Session::Session (AudioEngine &eng, _session_dir ( new SessionDirectory(fullpath)), pending_events (2048), state_tree (0), + butler (new Butler ()), post_transport_work((PostTransportWork)0), _send_smpte_update (false), midi_thread (pthread_t (0)), @@ -350,7 +353,7 @@ Session::destroy () delete state_tree; /* reset dynamic state version back to default */ - + Stateful::loading_state_version = 0; terminate_butler_thread (); diff --git a/libs/ardour/session_butler.cc b/libs/ardour/session_butler.cc index 4f8f244c22..2a217e5630 100644 --- a/libs/ardour/session_butler.cc +++ b/libs/ardour/session_butler.cc @@ -33,6 +33,7 @@ #include "ardour/audio_diskstream.h" #include "ardour/audioengine.h" +#include "ardour/butler.h" #include "ardour/configuration.h" #include "ardour/crossfade.h" #include "ardour/io.h" @@ -82,29 +83,29 @@ Session::start_butler_thread () Crossfade::set_buffer_size (audio_dstream_buffer_size); - butler_should_run = false; + butler->should_run = false; - if (pipe (butler_request_pipe)) { + if (pipe (butler->request_pipe)) { error << string_compose(_("Cannot create transport request signal pipe (%1)"), strerror (errno)) << endmsg; return -1; } - if (fcntl (butler_request_pipe[0], F_SETFL, O_NONBLOCK)) { + if (fcntl (butler->request_pipe[0], F_SETFL, O_NONBLOCK)) { error << string_compose(_("UI: cannot set O_NONBLOCK on butler request pipe (%1)"), strerror (errno)) << endmsg; return -1; } - if (fcntl (butler_request_pipe[1], F_SETFL, O_NONBLOCK)) { + if (fcntl (butler->request_pipe[1], F_SETFL, O_NONBLOCK)) { error << string_compose(_("UI: cannot set O_NONBLOCK on butler request pipe (%1)"), strerror (errno)) << endmsg; return -1; } - if (pthread_create_and_store ("disk butler", &butler_thread, 0, _butler_thread_work, this)) { + if (pthread_create_and_store ("disk butler", &butler->thread, 0, _butler_thread_work, this)) { error << _("Session: could not create butler thread") << endmsg; return -1; } - // pthread_detach (butler_thread); + // pthread_detach (butler->thread); return 0; } @@ -112,18 +113,18 @@ Session::start_butler_thread () void Session::terminate_butler_thread () { - if (butler_thread) { + if (butler->thread) { void* status; char c = ButlerRequest::Quit; - ::write (butler_request_pipe[1], &c, 1); - pthread_join (butler_thread, &status); + ::write (butler->request_pipe[1], &c, 1); + pthread_join (butler->thread, &status); } } void Session::schedule_butler_transport_work () { - g_atomic_int_inc (&butler_should_do_transport_work); + g_atomic_int_inc (&butler->should_do_transport_work); summon_butler (); } @@ -138,26 +139,26 @@ void Session::summon_butler () { char c = ButlerRequest::Run; - ::write (butler_request_pipe[1], &c, 1); + ::write (butler->request_pipe[1], &c, 1); // PBD::stacktrace (cerr); } void Session::stop_butler () { - Glib::Mutex::Lock lm (butler_request_lock); + Glib::Mutex::Lock lm (butler->request_lock); char c = ButlerRequest::Pause; - ::write (butler_request_pipe[1], &c, 1); - butler_paused.wait(butler_request_lock); + ::write (butler->request_pipe[1], &c, 1); + butler->paused.wait(butler->request_lock); } void Session::wait_till_butler_finished () { - Glib::Mutex::Lock lm (butler_request_lock); + Glib::Mutex::Lock lm (butler->request_lock); char c = ButlerRequest::Wake; - ::write (butler_request_pipe[1], &c, 1); - butler_paused.wait(butler_request_lock); + ::write (butler->request_pipe[1], &c, 1); + butler->paused.wait(butler->request_lock); } void * @@ -181,7 +182,7 @@ Session::butler_thread_work () DiskstreamList::iterator i; while (true) { - pfd[0].fd = butler_request_pipe[0]; + pfd[0].fd = butler->request_pipe[0]; pfd[0].events = POLLIN|POLLERR|POLLHUP; if (poll (pfd, 1, (disk_work_outstanding ? 0 : -1)) < 0) { @@ -208,7 +209,7 @@ Session::butler_thread_work () /* empty the pipe of all current requests */ while (1) { - size_t nread = ::read (butler_request_pipe[0], &req, sizeof (req)); + size_t nread = ::read (butler->request_pipe[0], &req, sizeof (req)); if (nread == 1) { switch ((ButlerRequest::Type) req) { @@ -217,11 +218,11 @@ Session::butler_thread_work () break; case ButlerRequest::Run: - butler_should_run = true; + butler->should_run = true; break; case ButlerRequest::Pause: - butler_should_run = false; + butler->should_run = false; break; case ButlerRequest::Quit: @@ -260,7 +261,7 @@ Session::butler_thread_work () // cerr << "BEFORE " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl; // } - for (i = dsl->begin(); !transport_work_requested() && butler_should_run && i != dsl->end(); ++i) { + for (i = dsl->begin(); !transport_work_requested() && butler->should_run && i != dsl->end(); ++i) { boost::shared_ptr<Diskstream> ds = *i; @@ -310,7 +311,7 @@ Session::butler_thread_work () compute_io = true; begin = get_microseconds(); - for (i = dsl->begin(); !transport_work_requested() && butler_should_run && i != dsl->end(); ++i) { + for (i = dsl->begin(); !transport_work_requested() && butler->should_run && i != dsl->end(); ++i) { // cerr << "write behind for " << (*i)->name () << endl; /* note that we still try to flush diskstreams attached to inactive routes @@ -367,9 +368,9 @@ Session::butler_thread_work () { - Glib::Mutex::Lock lm (butler_request_lock); + Glib::Mutex::Lock lm (butler->request_lock); - if (butler_should_run && (disk_work_outstanding || transport_work_requested())) { + if (butler->should_run && (disk_work_outstanding || transport_work_requested())) { // for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) { // cerr << "AFTER " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl; // } @@ -377,7 +378,7 @@ Session::butler_thread_work () continue; } - butler_paused.signal(); + butler->paused.signal(); } } @@ -467,9 +468,14 @@ Session::reset_capture_load_min () g_atomic_int_set (&_capture_load_min, 100); } - void Session::reset_playback_load_min () { g_atomic_int_set (&_playback_load_min, 100); } + +bool +Session::transport_work_requested () const +{ + return g_atomic_int_get(&butler->should_do_transport_work); +} diff --git a/libs/ardour/session_export.cc b/libs/ardour/session_export.cc index 77f0d89d97..764898875b 100644 --- a/libs/ardour/session_export.cc +++ b/libs/ardour/session_export.cc @@ -22,15 +22,16 @@ #include "pbd/error.h" #include <glibmm/thread.h> -#include "ardour/session.h" #include "ardour/audio_diskstream.h" #include "ardour/audioengine.h" +#include "ardour/butler.h" #include "ardour/export_failed.h" #include "ardour/export_file_io.h" #include "ardour/export_handler.h" #include "ardour/export_status.h" #include "ardour/export_utilities.h" #include "ardour/route.h" +#include "ardour/session.h" #include "i18n.h" @@ -137,7 +138,7 @@ Session::start_audio_export (nframes_t position, bool realtime) set_transport_speed (1.0, false); butler_transport_work (); - g_atomic_int_set (&butler_should_do_transport_work, 0); + g_atomic_int_set (&butler->should_do_transport_work, 0); post_transport (); /* we are ready to go ... */ diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index a192013717..4fc35fc964 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -202,7 +202,6 @@ Session::first_stage_init (string fullpath, string snapshot_name) session_send_mmc = false; session_send_mtc = false; post_transport_work = PostTransportWork (0); - g_atomic_int_set (&butler_should_do_transport_work, 0); g_atomic_int_set (&_playback_load, 100); g_atomic_int_set (&_capture_load, 100); g_atomic_int_set (&_playback_load_min, 100); @@ -217,7 +216,6 @@ Session::first_stage_init (string fullpath, string snapshot_name) destructive_index = 0; first_file_data_format_reset = true; first_file_header_format_reset = true; - butler_thread = (pthread_t) 0; //midi_thread = (pthread_t) 0; AudioDiskstream::allocate_working_buffers(); diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index ff36e30743..755202718b 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -35,12 +35,13 @@ #include "midi++/port.h" #include "ardour/ardour.h" -#include "ardour/audioengine.h" -#include "ardour/session.h" #include "ardour/audio_diskstream.h" +#include "ardour/audioengine.h" #include "ardour/auditioner.h" -#include "ardour/slave.h" +#include "ardour/butler.h" #include "ardour/location.h" +#include "ardour/session.h" +#include "ardour/slave.h" #include "i18n.h" @@ -193,7 +194,7 @@ Session::butler_transport_work () boost::shared_ptr<RouteList> r = routes.reader (); boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader(); - int on_entry = g_atomic_int_get (&butler_should_do_transport_work); + int on_entry = g_atomic_int_get (&butler->should_do_transport_work); finished = true; if (post_transport_work & PostTransportCurveRealloc) { @@ -226,9 +227,9 @@ Session::butler_transport_work () if (!(*i)->hidden()) { (*i)->non_realtime_locate (_transport_frame); } - if (on_entry != g_atomic_int_get (&butler_should_do_transport_work)) { + if (on_entry != g_atomic_int_get (&butler->should_do_transport_work)) { /* new request, stop seeking, and start again */ - g_atomic_int_dec_and_test (&butler_should_do_transport_work); + g_atomic_int_dec_and_test (&butler->should_do_transport_work); goto restart; } } @@ -242,7 +243,7 @@ Session::butler_transport_work () if (post_transport_work & PostTransportStop) { non_realtime_stop (post_transport_work & PostTransportAbort, on_entry, finished); if (!finished) { - g_atomic_int_dec_and_test (&butler_should_do_transport_work); + g_atomic_int_dec_and_test (&butler->should_do_transport_work); goto restart; } } @@ -250,7 +251,7 @@ Session::butler_transport_work () if (post_transport_work & PostTransportOverWrite) { non_realtime_overwrite (on_entry, finished); if (!finished) { - g_atomic_int_dec_and_test (&butler_should_do_transport_work); + g_atomic_int_dec_and_test (&butler->should_do_transport_work); goto restart; } } @@ -259,7 +260,7 @@ Session::butler_transport_work () non_realtime_set_audition (); } - g_atomic_int_dec_and_test (&butler_should_do_transport_work); + g_atomic_int_dec_and_test (&butler->should_do_transport_work); } void @@ -281,7 +282,7 @@ Session::non_realtime_overwrite (int on_entry, bool& finished) if ((*i)->pending_overwrite) { (*i)->overwrite_existing_buffers (); } - if (on_entry != g_atomic_int_get (&butler_should_do_transport_work)) { + if (on_entry != g_atomic_int_get (&butler->should_do_transport_work)) { finished = false; return; } @@ -431,7 +432,7 @@ Session::non_realtime_stop (bool abort, int on_entry, bool& finished) if (!(*i)->hidden()) { (*i)->non_realtime_locate (_transport_frame); } - if (on_entry != g_atomic_int_get (&butler_should_do_transport_work)) { + if (on_entry != g_atomic_int_get (&butler->should_do_transport_work)) { finished = false; /* we will be back */ return; @@ -1277,7 +1278,7 @@ Session::engine_halted () the picture. */ - g_atomic_int_set (&butler_should_do_transport_work, 0); + g_atomic_int_set (&butler->should_do_transport_work, 0); post_transport_work = PostTransportWork (0); stop_butler (); diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 3711d631fc..bb6869b048 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -60,6 +60,7 @@ libardour_sources = [ 'buffer.cc', 'buffer_set.cc', 'bundle.cc', + 'butler.cc', 'chan_count.cc', 'chan_mapping.cc', 'configuration.cc', |