Split butler into separate object (partially, just data so far...)
authorDavid Robillard <d@drobilla.net>
Fri, 23 Oct 2009 23:23:00 +0000 (23:23 +0000)
committerDavid Robillard <d@drobilla.net>
Fri, 23 Oct 2009 23:23:00 +0000 (23:23 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@5900 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/butler.h [new file with mode: 0644]
libs/ardour/ardour/session.h
libs/ardour/butler.cc [new file with mode: 0644]
libs/ardour/session.cc
libs/ardour/session_butler.cc
libs/ardour/session_export.cc
libs/ardour/session_state.cc
libs/ardour/session_transport.cc
libs/ardour/wscript

diff --git a/libs/ardour/ardour/butler.h b/libs/ardour/ardour/butler.h
new file mode 100644 (file)
index 0000000..524651b
--- /dev/null
@@ -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__
index 0e543462aef36b4b1992e351e1fb85ef28a0e6ad..aa15f07e8d38cab18e01de7763c5bb2287341c65 100644 (file)
@@ -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 (file)
index 0000000..33811ca
--- /dev/null
@@ -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
index e4de8ea6c4d55ea6c0dc7ec79f0f86164f3d04a2..a42d764c9ee5f9f2a66ef93dfdb3130f3037e5a7 100644 (file)
@@ -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 ();
index 4f8f244c223c9c5c76fb5e67aefe36565f749ce6..2a217e5630db2cd8098339424f75a7be6e02310e 100644 (file)
@@ -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);
+}
index 77f0d89d9728448f26825b15c2acc64ba216041c..764898875b28e5481a2c34388ce2bbcab3660488 100644 (file)
 #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 ... */
index a19201371762291d999c3fa3c96eeb9aa5995e9c..4fc35fc96408e8e94c41d7f22414797d46632096 100644 (file)
@@ -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();
index ff36e30743e7750453b48f4ab64d2c85e2262b0b..755202718b456f00b0f1f68162608916e7791711 100644 (file)
 #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 ();
 
index 3711d631fc2dd6803a588edbad6b091d2e992a83..bb6869b0487432bafc1e05ef2ad89f6a98ae7d8e 100644 (file)
@@ -60,6 +60,7 @@ libardour_sources = [
        'buffer.cc',
        'buffer_set.cc',
        'bundle.cc',
+       'butler.cc',
        'chan_count.cc',
        'chan_mapping.cc',
        'configuration.cc',