File: fluid-mutex.diff

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 218,192 kB
  • sloc: cpp: 291,369; xml: 200,226; sh: 3,779; ansic: 1,447; python: 393; makefile: 249; perl: 82; pascal: 79
file content (86 lines) | stat: -rw-r--r-- 2,777 bytes parent folder | download
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
Description: avoid UB (destroying a locked mutex)
 Unlock it just before end of holder’s destructor; ensure all
 callers won’t use it again.
Author: mirabilos <tg@debian.org>
Forwarded: no

--- a/fluid/fluid.cpp
+++ b/fluid/fluid.cpp
@@ -121,6 +121,7 @@ Fluid::~Fluid()
       qDeleteAll(sfonts);
       qDeleteAll(channel);
       qDeleteAll(patches);
+      mutex.unlock();
       }
 
 //---------------------------------------------------------
@@ -406,6 +407,8 @@ void Fluid::update_presets()
 
 void Fluid::process(unsigned len, float* out, float* effect1, float* effect2)
       {
+      if (_globalTerminate)
+            return;
       if (mutex.tryLock()) {
             //we have to copy voices array for proper output sound processing in for loop
             auto tempVoices = activeVoices;
@@ -641,6 +644,8 @@ bool Fluid::loadSoundFonts(const QString
             qDebug("Fluid:loadSoundFonts: already loaded");
             return true;
             }
+      if (_globalTerminate)
+            return false;
       QMutexLocker locker(&mutex);
       for(Voice* v : activeVoices)
             v->off();
@@ -688,6 +693,8 @@ bool Fluid::loadSoundFonts(const QString
 
 bool Fluid::addSoundFont(const QString& s)
       {
+      if (_globalTerminate)
+            return false;
       QMutexLocker locker(&mutex);
       bool rv = (sfload(s) == -1) ? false : true;
       return rv;
@@ -700,6 +707,8 @@ bool Fluid::addSoundFont(const QString&
 
 bool Fluid::removeSoundFont(const QString& s)
       {
+      if (_globalTerminate)
+            return false;
       QMutexLocker locker(&mutex);
       for(Voice* v : activeVoices)
             v->off();
--- a/fluid/fluid.h
+++ b/fluid/fluid.h
@@ -418,7 +418,6 @@ class Fluid : public Synthesizer {
       static QFileInfoList sfFiles();
 
       bool globalTerminate() { return _globalTerminate; }
-      void setGlobalTerminate(bool terminate = true) { _globalTerminate = terminate; }
 
       friend class Voice;
       friend class Preset;
--- a/fluid/sfont.cpp
+++ b/fluid/sfont.cpp
@@ -146,6 +146,12 @@ void Preset::loadSamples()
       {
       bool locked = sfont->synth->mutex.tryLock();
 
+      if (sfont->synth->globalTerminate()) {
+            if (locked)
+                  sfont->synth->mutex.unlock();
+            return;
+            }
+
       if (_global_zone && _global_zone->instrument) {
             Instrument* i = _global_zone->instrument;
             if (i->global_zone && i->global_zone->sample)
@@ -168,7 +174,7 @@ void Preset::loadSamples()
                         if (locked)
                               sfont->synth->mutex.unlock();
                         return;
-                  }
+                        }
 
                   iz->sample->load();
                   }