aboutsummaryrefslogtreecommitdiff
path: root/src/chips/java/JavaOPL3.hpp
diff options
context:
space:
mode:
authorVitaly Novichkov <Wohlstand@users.noreply.github.com>2019-02-24 13:46:11 +0300
committerGitHub <noreply@github.com>2019-02-24 13:46:11 +0300
commitcb465d27025c3fc594025fdefd1f83bf642b61f6 (patch)
tree1deab9d03d7189f1be6d18f3b53a743ea79896d0 /src/chips/java/JavaOPL3.hpp
parent48dabfa6f8efc25910eb73bfdcb024dd439dd2fd (diff)
parent432a19d45b1b285184a1000c6d528fcb0f360f7f (diff)
downloadlibADLMIDI-cb465d27025c3fc594025fdefd1f83bf642b61f6.tar.gz
libADLMIDI-cb465d27025c3fc594025fdefd1f83bf642b61f6.tar.bz2
libADLMIDI-cb465d27025c3fc594025fdefd1f83bf642b61f6.zip
Merge pull request #209 from jpcima/javaopl3
Javaopl3
Diffstat (limited to 'src/chips/java/JavaOPL3.hpp')
-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;
+ }
}
}