1 // synthv1_sched.h
2 //
3 /****************************************************************************
4    Copyright (C) 2012-2019, rncbc aka Rui Nuno Capela. All rights reserved.
5 
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    as published by the Free Software Foundation; either version 2
9    of the License, or (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License along
17    with this program; if not, write to the Free Software Foundation, Inc.,
18    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 
20 *****************************************************************************/
21 
22 #ifndef __synthv1_sched_h
23 #define __synthv1_sched_h
24 
25 #include <stdint.h>
26 
27 // forward decls.
28 class synthv1;
29 
30 
31 //-------------------------------------------------------------------------
32 // synthv1_sched - worker/scheduled stuff (pure virtual).
33 //
34 
35 class synthv1_sched
36 {
37 public:
38 
39 	// plausible sched types.
40 	enum Type { Wave, Programs, Controls, Controller, MidiIn };
41 
42 	// ctor.
43 	synthv1_sched(synthv1 *pSynth, Type stype, uint32_t nsize = 8);
44 
45 	// virtual dtor.
46 	virtual ~synthv1_sched();
47 
48 	// instance access.
49 	synthv1 *instance() const;
50 
51 	// schedule process.
52 	void schedule(int sid = 0);
53 
54 	// test-and-set wait.
55 	bool sync_wait();
56 
57 	// scheduled processor.
58 	void sync_process();
59 
60 	// (pure) virtual processor.
61 	virtual void process(int sid) = 0;
62 
63 	// signal broadcast (static).
64 	static void sync_notify(synthv1 *pSynth, Type stype, int sid);
65 
66 	// Notifier - Worker/schedule proxy decl.
67 	//
68 	class Notifier
69 	{
70 	public:
71 
72 		// ctor.
73 		Notifier(synthv1 *pSynth);
74 
75 		// dtor.
76 		virtual ~Notifier();
77 
78 		// signal notifier.
79 		virtual void notify(synthv1_sched::Type stype, int sid) const = 0;
80 
81 	private:
82 
83 		// instance variables.
84 		synthv1 *m_pSynth;
85 	};
86 
87 private:
88 
89 	// instance variables.
90 	synthv1 *m_pSynth;
91 
92 	Type m_stype;
93 
94 	// sched queue instance reference.
95 	uint32_t m_nsize;
96 	uint32_t m_nmask;
97 
98 	int *m_items;
99 
100 	volatile uint32_t m_iread;
101 	volatile uint32_t m_iwrite;
102 
103 	volatile bool m_sync_wait;
104 };
105 
106 
107 #endif	// __synthv1_sched_h
108 
109 // end of synthv1_sched.h
110