remove unused semaphore
[ardour.git] / libs / ardour / ardour / graph.h
1 /*
2     Copyright (C) 2010 Paul Davis
3     Author: Torben Hohn
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #ifndef __ardour_graph_h__
22 #define __ardour_graph_h__
23
24 #include <list>
25 #include <set>
26 #include <vector>
27 #include <string>
28
29 #include <boost/shared_ptr.hpp>
30
31 #include <glib.h>
32
33 #include "pbd/semutils.h"
34
35 #include "ardour/libardour_visibility.h"
36 #include "ardour/types.h"
37 #include "ardour/audio_backend.h"
38 #include "ardour/session_handle.h"
39
40 namespace ARDOUR
41 {
42
43 class GraphNode;
44 class Graph;
45
46 class Route;
47 class Session;
48 class GraphEdges;
49
50 typedef boost::shared_ptr<GraphNode> node_ptr_t;
51
52 typedef std::list< node_ptr_t > node_list_t;
53 typedef std::set< node_ptr_t > node_set_t;
54
55 class LIBARDOUR_API Graph : public SessionHandleRef
56 {
57 public:
58         Graph (Session & session);
59
60         void trigger (GraphNode * n);
61         void rechain (boost::shared_ptr<RouteList>, GraphEdges const &);
62
63         void dump (int chain);
64         void dec_ref();
65
66         void helper_thread();
67
68         int silent_process_routes (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
69                                    bool& need_butler);
70
71         int process_routes (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick,
72                             bool& need_butler);
73
74         int routes_no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
75                             bool non_rt_pending, int declick);
76
77         void process_one_route (Route * route);
78
79         void clear_other_chain ();
80
81         bool in_process_thread () const;
82
83 protected:
84         virtual void session_going_away ();
85
86 private:
87         volatile bool        _threads_active;
88
89         void reset_thread_list ();
90         void drop_threads ();
91         void restart_cycle();
92         bool run_one();
93         void main_thread();
94         void prep();
95
96         node_list_t _nodes_rt[2];
97
98         node_list_t _init_trigger_list[2];
99
100         std::vector<GraphNode *> _trigger_queue;
101         pthread_mutex_t          _trigger_mutex;
102
103         PBD::Semaphore _execution_sem;
104
105         /** Signalled to start a run of the graph for a process callback */
106         PBD::Semaphore _callback_start_sem;
107         PBD::Semaphore _callback_done_sem;
108
109         /** The number of processing threads that are asleep */
110         volatile gint _execution_tokens;
111         /** The number of unprocessed nodes that do not feed any other node; updated during processing */
112         volatile gint _finished_refcount;
113         /** The initial number of nodes that do not feed any other node (for each chain) */
114         volatile gint _init_finished_refcount[2];
115
116         bool _graph_empty;
117
118         // chain swapping
119         Glib::Threads::Mutex  _swap_mutex;
120         Glib::Threads::Cond   _cleanup_cond;
121         volatile int _current_chain;
122         volatile int _pending_chain;
123         volatile int _setup_chain;
124
125         // parameter caches.
126         pframes_t  _process_nframes;
127         framepos_t _process_start_frame;
128         framepos_t _process_end_frame;
129         bool       _process_can_record;
130         bool       _process_non_rt_pending;
131         int        _process_declick;
132
133         bool _process_silent;
134         bool _process_noroll;
135         int  _process_retval;
136         bool _process_need_butler;
137
138         // enginer / thread connection
139         PBD::ScopedConnectionList engine_connections;
140         void engine_stopped ();
141 };
142
143 } // namespace
144
145 #endif /* __ardour_graph_h__ */