Skip to content

Commit 275f21b

Browse files
committed
Add mutex around gInstancesMutex
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 9b2b7ee commit 275f21b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

JackAss.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,19 @@ class JackAssInstance
173173
// static list of JackAss instances
174174

175175
static std::list<JackAssInstance*> gInstances;
176+
static pthread_mutex_t gInstancesMutex = PTHREAD_MUTEX_INITIALIZER;
176177

177178
// -------------------------------------------------
178179
// JACK calls
179180

180181
static int jprocess_callback(const jack_nframes_t nframes, void*)
181182
{
183+
pthread_mutex_lock(&gInstancesMutex);
184+
182185
for (std::list<JackAssInstance*>::iterator it = gInstances.begin(), end = gInstances.end(); it != end; ++it)
183186
(*it)->jprocess(nframes);
187+
188+
pthread_mutex_unlock(&gInstancesMutex);
184189
return 0;
185190
}
186191

@@ -278,7 +283,10 @@ class JackAss : public AudioEffectX
278283
if (jack_port_t* const jport = jackbridge_port_register(gJackClient, strBuf, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0))
279284
{
280285
fInstance = new JackAssInstance(jport);
286+
287+
pthread_mutex_lock(&gInstancesMutex);
281288
gInstances.push_back(fInstance);
289+
pthread_mutex_unlock(&gInstancesMutex);
282290
}
283291
}
284292

@@ -297,7 +305,10 @@ class JackAss : public AudioEffectX
297305

298306
if (fInstance != nullptr)
299307
{
308+
pthread_mutex_lock(&gInstancesMutex);
300309
gInstances.remove(fInstance);
310+
pthread_mutex_unlock(&gInstancesMutex);
311+
301312
delete fInstance;
302313
fInstance = nullptr;
303314
}

0 commit comments

Comments
 (0)