aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth/fmtowns_pc98/pc98_audio.cpp
diff options
context:
space:
mode:
authorathrxx2019-11-10 15:24:41 +0100
committerathrxx2019-12-18 20:50:39 +0100
commit21b5f9262c14114f457120a0504a55fc3ca96489 (patch)
treecebb9eae8918ef1069cdbb2171021c71f4606ae9 /audio/softsynth/fmtowns_pc98/pc98_audio.cpp
parent1083b94cbfbf687b40d487ab2530be9fb1556b1a (diff)
downloadscummvm-rg350-21b5f9262c14114f457120a0504a55fc3ca96489.tar.gz
scummvm-rg350-21b5f9262c14114f457120a0504a55fc3ca96489.tar.bz2
scummvm-rg350-21b5f9262c14114f457120a0504a55fc3ca96489.zip
AUDIO: (FM-TOWNS/PC-98) - fix regression from 0e734722
My commit 0e734722 causes lockups in SCUMM (sometimes) and SCI (very often). I didn't like the way I had fixed this before, but in the end I now had to do it in a similar way.
Diffstat (limited to 'audio/softsynth/fmtowns_pc98/pc98_audio.cpp')
-rw-r--r--audio/softsynth/fmtowns_pc98/pc98_audio.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/audio/softsynth/fmtowns_pc98/pc98_audio.cpp b/audio/softsynth/fmtowns_pc98/pc98_audio.cpp
index 9ab1ec7659..144e9834b0 100644
--- a/audio/softsynth/fmtowns_pc98/pc98_audio.cpp
+++ b/audio/softsynth/fmtowns_pc98/pc98_audio.cpp
@@ -47,6 +47,7 @@ public:
void ssgSetVolume(int volume);
Common::Mutex &mutex();
+ int mixerThreadLockCounter() const;
private:
bool assignPluginDriver(PC98AudioCore *owner, PC98AudioPluginDriver *driver, bool externalMutexHandling = false);
@@ -192,6 +193,10 @@ Common::Mutex &PC98AudioCoreInternal::mutex() {
return _mutex;
}
+int PC98AudioCoreInternal::mixerThreadLockCounter() const {
+ return _mixerThreadLockCounter;
+}
+
bool PC98AudioCoreInternal::assignPluginDriver(PC98AudioCore *owner, PC98AudioPluginDriver *driver, bool externalMutexHandling) {
Common::StackLock lock(_mutex);
if (_refCount <= 1)
@@ -215,13 +220,11 @@ void PC98AudioCoreInternal::removePluginDriver(PC98AudioCore *owner) {
}
void PC98AudioCoreInternal::timerCallbackA() {
- Common::StackLock lock(_mutex);
if (_drv && _ready)
_drv->timerCallbackA();
}
void PC98AudioCoreInternal::timerCallbackB() {
- Common::StackLock lock(_mutex);
if (_drv && _ready)
_drv->timerCallbackB();
}
@@ -283,12 +286,30 @@ PC98AudioCore::MutexLock PC98AudioCore::stackLockMutex() {
return MutexLock(_internal);
}
-PC98AudioCore::MutexLock::MutexLock(PC98AudioCoreInternal *pc98int) : _pc98int(pc98int) {
- if (_pc98int)
+PC98AudioCore::MutexLock PC98AudioCore::stackUnlockMutex() {
+ return MutexLock(_internal, _internal->mixerThreadLockCounter());
+}
+
+PC98AudioCore::MutexLock::MutexLock(PC98AudioCoreInternal *pc98int, int reverse) : _pc98int(pc98int), _count(reverse) {
+ if (!_pc98int)
+ return;
+
+ if (!reverse) {
_pc98int->mutex().lock();
+ return;
+ }
+
+ while (reverse--)
+ _pc98int->mutex().unlock();
}
PC98AudioCore::MutexLock::~MutexLock() {
- if (_pc98int)
+ if (!_pc98int)
+ return;
+
+ if (!_count)
_pc98int->mutex().unlock();
+
+ while (_count--)
+ _pc98int->mutex().lock();
}