aboutsummaryrefslogtreecommitdiff
path: root/audio/seq24/01-mutex.patch
blob: 4e8585a94491d55f2d63ab27c2ba979d6ef73289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
Description: Use standard mutex and condition variable classes
 Use std::recursive_mutex and std::condition_variable instead of custom classes
 based on pthread.
 .
 Fixes FTBFS with recent GCC versions which defines the "mutex" class which
 conflicts with seq24's version of "mutex".
Author: James Cowgill <jcowgill@debian.org>
Bug: https://bugs.launchpad.net/seq24/+bug/1647614
Bug-Debian: https://bugs.debian.org/822394
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/Module.am
+++ b/src/Module.am
@@ -31,8 +31,6 @@ bin_PROGRAMS = %D%/seq24
   %D%/midibus_portmidi.h \
   %D%/midifile.cpp \
   %D%/midifile.h \
-  %D%/mutex.cpp \
-  %D%/mutex.h \
   %D%/options.cpp \
   %D%/options.h \
   %D%/optionsfile.cpp \
--- a/src/midibus.h
+++ b/src/midibus.h
@@ -35,11 +35,11 @@ class midibus;
 #    include <alsa/seq_midi_event.h>
 #endif
 
+#include <mutex>
 #include <string>
 
 #include "event.h"
 #include "sequence.h"
-#include "mutex.h"
 #include "globals.h"
 
 const int c_midibus_output_size = 0x100000;
@@ -90,7 +90,7 @@ class midibus
 
 
     /* locking */
-    mutex m_mutex;
+    std::recursive_mutex m_mutex;
 
     /* mutex */
     void lock();
@@ -208,7 +208,7 @@ class mastermidibus
     sequence *m_seq;
 
     /* locking */
-    mutex m_mutex;
+    std::recursive_mutex m_mutex;
 
     /* mutex */
     void lock();
--- a/src/midibus_portmidi.h
+++ b/src/midibus_portmidi.h
@@ -25,12 +25,12 @@ class mastermidibus;
 
 #ifdef __WIN32__
 
+#include <mutex>
 #include <string>
 
 #include "portmidi.h"
 #include "event.h"
 #include "sequence.h"
-#include "mutex.h"
 #include "globals.h"
 
 const int c_midibus_output_size = 0x100000;
@@ -65,7 +65,7 @@ class midibus
     long m_lasttick;
 
     /* locking */
-    mutex m_mutex;
+    std::recursive_mutex m_mutex;
 
     /* mutex */
     void lock();
@@ -164,7 +164,7 @@ class mastermidibus
     sequence *m_seq;
 
     /* locking */
-    mutex m_mutex;
+    std::recursive_mutex m_mutex;
 
     /* mutex */
     void lock();
--- a/src/mutex.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-//----------------------------------------------------------------------------
-//
-//  This file is part of seq24.
-//
-//  seq24 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.
-//
-//  seq24 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 seq24; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-//
-//-----------------------------------------------------------------------------
-
-#include "mutex.h"
-
-const pthread_mutex_t mutex::recmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-const pthread_cond_t condition_var::cond  = PTHREAD_COND_INITIALIZER;
-
-mutex::mutex( )
-{
-    m_mutex_lock = recmutex;
-}
-
-void
-mutex::lock( )
-{
-    pthread_mutex_lock( &m_mutex_lock );
-}
-
-
-void
-mutex::unlock( )
-{
-    pthread_mutex_unlock( &m_mutex_lock );
-}
-
-condition_var::condition_var( )
-{
-    m_cond = cond;
-}
-
-
-void
-condition_var::signal( )
-{
-    pthread_cond_signal( &m_cond );
-}
-
-void
-condition_var::wait( )
-{
-    pthread_cond_wait( &m_cond, &m_mutex_lock );
-}
-
-
--- a/src/mutex.h
+++ /dev/null
@@ -1,63 +0,0 @@
-//----------------------------------------------------------------------------
-//
-//  This file is part of seq24.
-//
-//  seq24 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.
-//
-//  seq24 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 seq24; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-//
-//-----------------------------------------------------------------------------
-
-#pragma once
-
-#include "globals.h"
-
-#include <pthread.h>
-
-class mutex {
-
-private:
-
-    static const pthread_mutex_t recmutex;
-
-protected:
-
-    /* mutex lock */
-    pthread_mutex_t  m_mutex_lock;
-
-public:
-
-    mutex();
-
-    void lock();
-    void unlock();
-
-};
-
-class condition_var : public mutex {
-
-private:
-
-    static const pthread_cond_t cond;
-
-    pthread_cond_t m_cond;
-
-public:
-
-    condition_var();
-
-    void wait();
-    void signal();
-
-};
-
--- a/src/perform.cpp
+++ b/src/perform.cpp
@@ -426,7 +426,7 @@ perform::~perform()
     m_outputing = false;
     m_running = false;
 
-    m_condition_var.signal();
+    m_condition_var.notify_one();
 
     if (m_out_thread_launched )
         pthread_join( m_out_thread, NULL );
@@ -1005,7 +1005,7 @@ void perform::stop()
 
 void perform::inner_start(bool a_state)
 {
-    m_condition_var.lock();
+    std::lock_guard<std::mutex> lock(m_mutex);
 
     if (!is_running()) {
 
@@ -1015,10 +1015,8 @@ void perform::inner_start(bool a_state)
             off_sequences();
 
         set_running(true);
-        m_condition_var.signal();
+        m_condition_var.notify_one();
     }
-
-    m_condition_var.unlock();
 }
 
 
@@ -1262,18 +1260,18 @@ void perform::output_func()
 
         //printf ("waiting for signal\n");
 
-        m_condition_var.lock();
+        std::unique_lock<std::mutex> lock(m_mutex);
 
         while (!m_running) {
 
-            m_condition_var.wait();
+            m_condition_var.wait(lock);
 
             /* if stopping, then kill thread */
             if (!m_outputing)
                 break;
         }
 
-        m_condition_var.unlock();
+        lock.unlock();
 
         //printf( "signaled [%d]\n", m_playback_mode );
 
--- a/src/perform.h
+++ b/src/perform.h
@@ -32,6 +32,9 @@ class perform;
 #endif
 #include <pthread.h>
 
+#include <condition_variable>
+#include <mutex>
+
 
 /* if we have jack, include the jack headers */
 #ifdef JACK_SUPPORT
@@ -152,7 +155,8 @@ class perform
     int m_control_status;
     int m_screen_set;
 
-    condition_var m_condition_var;
+    std::condition_variable m_condition_var;
+    std::mutex m_mutex;
 
     // do not access these directly, use set/lookup below
     std::map<unsigned int,long> key_events;
--- a/src/perfroll.h
+++ b/src/perfroll.h
@@ -39,8 +39,6 @@
 
 #include "globals.h"
 #include "perform.h"
-#include "mutex.h"
-
 
 using namespace Gtk;
 
--- a/src/sequence.h
+++ b/src/sequence.h
@@ -26,11 +26,11 @@ class sequence;
 #include <string>
 #include <list>
 #include <stack>
+#include <mutex>
 
 #include "event.h"
 #include "midibus.h"
 #include "globals.h"
-#include "mutex.h"
 
 enum draw_type
 {
@@ -153,7 +153,7 @@ class sequence
     long m_rec_vol;
 
     /* locking */
-    mutex m_mutex;
+    std::recursive_mutex m_mutex;
 
     /* used to idenfity which events are ours in the out queue */
     //unsigned char m_tag;