aboutsummaryrefslogtreecommitdiff
path: root/src/chips/java
diff options
context:
space:
mode:
authorJP Cimalando <jpcima@users.noreply.github.com>2019-02-24 11:02:33 +0100
committerJP Cimalando <jpcima@users.noreply.github.com>2019-02-24 11:02:33 +0100
commit2e61743ff0092032c2f2590b8333cea55758fd13 (patch)
tree152c59035a986baa5488c23b6ac4844ff9eb95d5 /src/chips/java
parent48751ca040600d80e92deecbabe61804e01a8ae7 (diff)
downloadlibADLMIDI-2e61743ff0092032c2f2590b8333cea55758fd13.tar.gz
libADLMIDI-2e61743ff0092032c2f2590b8333cea55758fd13.tar.bz2
libADLMIDI-2e61743ff0092032c2f2590b8333cea55758fd13.zip
javaopl3: thread safe initialization and cleanup
Diffstat (limited to 'src/chips/java')
-rw-r--r--src/chips/java/JavaOPL3.hpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/chips/java/JavaOPL3.hpp b/src/chips/java/JavaOPL3.hpp
index a18266a..df71cab 100644
--- a/src/chips/java/JavaOPL3.hpp
+++ b/src/chips/java/JavaOPL3.hpp
@@ -47,6 +47,7 @@
#include <stdint.h>
#include <string.h>
#include <limits>
+#include "../common/mutex.hpp"
#ifndef UINT32_MAX
#define UINT32_MAX 0xffffffffU
@@ -602,6 +603,7 @@ private:
void setRhythmMode();
static int InstanceCount;
+ static Mutex InstanceMutex;
// OPLEmul interface
public:
@@ -614,6 +616,7 @@ public:
OperatorDataStruct *OPL3::OperatorData;
OPL3DataStruct *OPL3::OPL3Data;
int OPL3::InstanceCount;
+Mutex OPL3::InstanceMutex;
void OPL3::Update(float *output, int numsamples) {
while (numsamples--) {
@@ -735,10 +738,13 @@ OPL3::OPL3(bool fullpan)
nts = dam = dvb = ryt = bd = sd = tom = tc = hh = _new = connectionsel = 0;
vibratoIndex = tremoloIndex = 0;
- if (InstanceCount++ == 0)
{
- OPL3Data = new struct OPL3DataStruct;
- OperatorData = new struct OperatorDataStruct;
+ MutexHolder lock(InstanceMutex);
+ if (InstanceCount++ == 0)
+ {
+ OPL3Data = new struct OPL3DataStruct;
+ OperatorData = new struct OperatorDataStruct;
+ }
}
initOperators();
@@ -770,12 +776,16 @@ OPL3::~OPL3()
delete channels4op[array][channelNumber];
}
}
- if (--InstanceCount == 0)
+
{
- delete OPL3Data;
- OPL3Data = NULL;
- delete OperatorData;
- OperatorData = NULL;
+ MutexHolder lock(InstanceMutex);
+ if (--InstanceCount == 0)
+ {
+ delete OPL3Data;
+ OPL3Data = NULL;
+ delete OperatorData;
+ OperatorData = NULL;
+ }
}
}