correctly track monitoring changes in libardour and the GUI; required removing propag...
[ardour.git] / libs / ardour / ardour / graph.h
index 6226ed56020dbecd25146432cf9bec01a0f5e9dc..0fa5b2f6c842e26c2336c1b301edbfcd94b80342 100644 (file)
@@ -1,6 +1,6 @@
 /*
     Copyright (C) 2010 Paul Davis
-    Author: Torben Hohn 
+    Author: Torben Hohn
 
     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
 #include <cassert>
 
 #include <pthread.h>
-#include <semaphore.h>
 
-#include <ardour/types.h>
-#include <ardour/session_handle.h>
+#include "pbd/semutils.h"
+
+#include "ardour/types.h"
+#include "ardour/session_handle.h"
 
 namespace ARDOUR
 {
@@ -54,9 +55,11 @@ typedef std::set< node_ptr_t > node_set_t;
 
 class Graph : public SessionHandleRef
 {
-    public:
+public:
        Graph (Session & session);
 
+       uint32_t threads_in_use () const { return _thread_list.size(); }
+
        void prep();
        void trigger (GraphNode * n);
        void rechain (boost::shared_ptr<RouteList> r);
@@ -70,64 +73,73 @@ class Graph : public SessionHandleRef
        void helper_thread();
        void main_thread();
 
-       int silent_process_routes (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
-                bool can_record, bool rec_monitors_input, bool& need_butler);
+       int silent_process_routes (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
+                                  bool& need_butler);
 
-       int process_routes (nframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick,
-                bool can_record, bool rec_monitors_input, bool& need_butler);
+       int process_routes (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick,
+                           bool& need_butler);
 
-        int routes_no_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame, 
-                bool non_rt_pending, bool can_record, int declick);
+       int routes_no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
+                           bool non_rt_pending, int declick);
 
        void process_one_route (Route * route);
 
-    protected:
-        virtual void session_going_away ();
+       void clear_other_chain ();
+
+       bool in_process_thread () const;
+
+protected:
+       virtual void session_going_away ();
+
+private:
+       std::list<pthread_t> _thread_list;
+       volatile bool        _quit_threads;
+       PBD::ScopedConnection processor_usage_connection;
+
+       void parameter_changed (std::string);
+       void reset_thread_list ();
+       void drop_threads ();
 
-    private:
-        std::list<Glib::Thread *> _thread_list;
-        volatile bool _quit_threads;
-        
        node_list_t _nodes_rt[2];
 
        node_list_t _init_trigger_list[2];
 
        std::vector<GraphNode *> _trigger_queue;
-       pthread_mutex_t _trigger_mutex;
-
+       pthread_mutex_t          _trigger_mutex;
 
-       sem_t _execution_sem;
+       PBD::ProcessSemaphore _execution_sem;
 
-       sem_t _callback_start_sem;
-       sem_t _callback_done_sem;
+       PBD::ProcessSemaphore _callback_start_sem;
+       PBD::ProcessSemaphore _callback_done_sem;
+       PBD::ProcessSemaphore _cleanup_sem;
 
        volatile gint _execution_tokens;
        volatile gint _finished_refcount;
        volatile gint _init_finished_refcount[2];
 
-        bool _graph_empty;
+       bool _graph_empty;
 
        // chain swapping
-       pthread_mutex_t _swap_mutex;
+       Glib::Mutex  _swap_mutex;
+       Glib::Cond   _cleanup_cond;
        volatile int _current_chain;
        volatile int _pending_chain;
        volatile int _setup_chain;
 
        // parameter caches.
-       nframes_t       _process_nframes;
-       framepos_t      _process_start_frame;
-       framepos_t      _process_end_frame;
-       bool            _process_can_record;
-       bool            _process_rec_monitors_input;
-       bool            _process_non_rt_pending;
-       int             _process_declick;
-
-       bool            _process_silent;
-       bool            _process_noroll;
-       int             _process_retval;
-       bool            _process_need_butler;
+       pframes_t  _process_nframes;
+       framepos_t _process_start_frame;
+       framepos_t _process_end_frame;
+       bool       _process_can_record;
+       bool       _process_non_rt_pending;
+       int        _process_declick;
+
+       bool _process_silent;
+       bool _process_noroll;
+       int      _process_retval;
+       bool _process_need_butler;
 };
 
-} // namespace 
+} // namespace
 
 #endif /* __ardour_graph_h__ */