Skip to content

Commit

Permalink
Add mutex around gInstancesMutex
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Jan 27, 2020
1 parent 9b2b7ee commit 275f21b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions JackAss.cpp
Expand Up @@ -173,14 +173,19 @@ class JackAssInstance
// static list of JackAss instances

static std::list<JackAssInstance*> gInstances;
static pthread_mutex_t gInstancesMutex = PTHREAD_MUTEX_INITIALIZER;

// -------------------------------------------------
// JACK calls

static int jprocess_callback(const jack_nframes_t nframes, void*)
{
pthread_mutex_lock(&gInstancesMutex);

for (std::list<JackAssInstance*>::iterator it = gInstances.begin(), end = gInstances.end(); it != end; ++it)
(*it)->jprocess(nframes);

pthread_mutex_unlock(&gInstancesMutex);
return 0;
}

Expand Down Expand Up @@ -278,7 +283,10 @@ class JackAss : public AudioEffectX
if (jack_port_t* const jport = jackbridge_port_register(gJackClient, strBuf, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0))
{
fInstance = new JackAssInstance(jport);

pthread_mutex_lock(&gInstancesMutex);
gInstances.push_back(fInstance);
pthread_mutex_unlock(&gInstancesMutex);
}
}

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

if (fInstance != nullptr)
{
pthread_mutex_lock(&gInstancesMutex);
gInstances.remove(fInstance);
pthread_mutex_unlock(&gInstancesMutex);

delete fInstance;
fInstance = nullptr;
}
Expand Down

0 comments on commit 275f21b

Please sign in to comment.