diff options
author | athrxx | 2019-08-03 22:23:24 +0200 |
---|---|---|
committer | athrxx | 2019-08-07 16:43:06 +0200 |
commit | 0e73472207b18e406f51e8bca9c3450dd908ec38 (patch) | |
tree | 676ca6131e65f5ec48668c4d01f63701ce7be0dc /audio/softsynth/fmtowns_pc98/pc98_audio.cpp | |
parent | 8b197e4ec70a52f91c0774be98acf5b373542bde (diff) | |
download | scummvm-rg350-0e73472207b18e406f51e8bca9c3450dd908ec38.tar.gz scummvm-rg350-0e73472207b18e406f51e8bca9c3450dd908ec38.tar.bz2 scummvm-rg350-0e73472207b18e406f51e8bca9c3450dd908ec38.zip |
AUDIO: (FM-Towns/PC98) - cleanup mutex handling
Diffstat (limited to 'audio/softsynth/fmtowns_pc98/pc98_audio.cpp')
-rw-r--r-- | audio/softsynth/fmtowns_pc98/pc98_audio.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/audio/softsynth/fmtowns_pc98/pc98_audio.cpp b/audio/softsynth/fmtowns_pc98/pc98_audio.cpp index 3ad100911a..c8d58f6923 100644 --- a/audio/softsynth/fmtowns_pc98/pc98_audio.cpp +++ b/audio/softsynth/fmtowns_pc98/pc98_audio.cpp @@ -26,11 +26,11 @@ class PC98AudioCoreInternal : public TownsPC98_FmSynth { private: - PC98AudioCoreInternal(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type, bool externalMutexHandling = false); + PC98AudioCoreInternal(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type); public: ~PC98AudioCoreInternal(); - static PC98AudioCoreInternal *addNewRef(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type, bool externalMutexHandling = false); + static PC98AudioCoreInternal *addNewRef(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type); static void releaseRef(PC98AudioCore *owner); bool init(); @@ -69,8 +69,8 @@ private: static int _refCount; }; -PC98AudioCoreInternal::PC98AudioCoreInternal(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type, bool externalMutexHandling) : - TownsPC98_FmSynth(mixer, (TownsPC98_FmSynth::EmuType)type, externalMutexHandling), +PC98AudioCoreInternal::PC98AudioCoreInternal(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type) : + TownsPC98_FmSynth(mixer, (TownsPC98_FmSynth::EmuType)type), _drv(driver), _drvOwner(owner), _musicVolume(Audio::Mixer::kMaxMixerVolume), _sfxVolume(Audio::Mixer::kMaxMixerVolume), _port1(type == PC98AudioPluginDriver::kTypeTowns ? 0x4D8 : 0x188), _port2(type == PC98AudioPluginDriver::kTypeTowns ? 0x4DA : 0x18A), @@ -80,22 +80,22 @@ PC98AudioCoreInternal::PC98AudioCoreInternal(Audio::Mixer *mixer, PC98AudioCore } PC98AudioCoreInternal::~PC98AudioCoreInternal() { + Common::StackLock lock(_mutex); _ready = false; deinit(); - Common::StackLock lock(_mutex); /* */ } -PC98AudioCoreInternal *PC98AudioCoreInternal::addNewRef(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type, bool externalMutexHandling) { +PC98AudioCoreInternal *PC98AudioCoreInternal::addNewRef(Audio::Mixer *mixer, PC98AudioCore *owner, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type) { _refCount++; if (_refCount == 1 && _refInstance == 0) - _refInstance = new PC98AudioCoreInternal(mixer, owner, driver, type, externalMutexHandling); + _refInstance = new PC98AudioCoreInternal(mixer, owner, driver, type); else if (_refCount < 2 || _refInstance == 0) error("PC98AudioCoreInternal::addNewRef(): Internal reference management failure"); - else if (!_refInstance->assignPluginDriver(owner, driver, externalMutexHandling)) + else if (!_refInstance->assignPluginDriver(owner, driver)) error("PC98AudioCoreInternal::addNewRef(): Plugin driver conflict"); return _refInstance; @@ -139,6 +139,7 @@ bool PC98AudioCoreInternal::init() { } void PC98AudioCoreInternal::writePort(uint16 port, uint8 value) { + Common::StackLock lock(_mutex); if (port == _port1) _address[0] = value; else if (port == _port2 && _address[0] < 0xc0) { @@ -153,6 +154,7 @@ void PC98AudioCoreInternal::writePort(uint16 port, uint8 value) { } uint8 PC98AudioCoreInternal::readPort(uint16 port) { + Common::StackLock lock(_mutex); uint8 val = 0; if (port == _port2 && _address[0] < 0xc0) { val = readReg(0, _address[0]); @@ -165,20 +167,24 @@ uint8 PC98AudioCoreInternal::readPort(uint16 port) { } void PC98AudioCoreInternal::setMusicVolume(int volume) { + Common::StackLock lock(_mutex); _musicVolume = CLIP<uint16>(volume, 0, Audio::Mixer::kMaxMixerVolume); setVolumeIntern(_musicVolume, _sfxVolume); } void PC98AudioCoreInternal::setSoundEffectVolume(int volume) { + Common::StackLock lock(_mutex); _sfxVolume = CLIP<uint16>(volume, 0, Audio::Mixer::kMaxMixerVolume); setVolumeIntern(_musicVolume, _sfxVolume); } void PC98AudioCoreInternal::setSoundEffectChanMask(int mask) { + Common::StackLock lock(_mutex); setVolumeChannelMasks(~mask, mask); } void PC98AudioCoreInternal::ssgSetVolume(int volume) { + Common::StackLock lock(_mutex); setLevelSSG(volume); } @@ -187,6 +193,7 @@ Common::Mutex &PC98AudioCoreInternal::mutex() { } bool PC98AudioCoreInternal::assignPluginDriver(PC98AudioCore *owner, PC98AudioPluginDriver *driver, bool externalMutexHandling) { + Common::StackLock lock(_mutex); if (_refCount <= 1) return true; @@ -194,28 +201,27 @@ bool PC98AudioCoreInternal::assignPluginDriver(PC98AudioCore *owner, PC98AudioPl if (driver && driver != _drv) return false; } else { - Common::StackLock lock(_mutex); _drv = driver; _drvOwner = owner; - _externalMutex = externalMutexHandling; } return true; } void PC98AudioCoreInternal::removePluginDriver(PC98AudioCore *owner) { - if (_drvOwner == owner) { - Common::StackLock lock(_mutex); + Common::StackLock lock(_mutex); + if (_drvOwner == owner) _drv = 0; - } } void PC98AudioCoreInternal::timerCallbackA() { + Common::StackLock lock(_mutex); if (_drv && _ready) _drv->timerCallbackA(); } void PC98AudioCoreInternal::timerCallbackB() { + Common::StackLock lock(_mutex); if (_drv && _ready) _drv->timerCallbackB(); } @@ -224,8 +230,8 @@ PC98AudioCoreInternal *PC98AudioCoreInternal::_refInstance = 0; int PC98AudioCoreInternal::_refCount = 0; -PC98AudioCore::PC98AudioCore(Audio::Mixer *mixer, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type, bool externalMutexHandling) { - _internal = PC98AudioCoreInternal::addNewRef(mixer, this, driver, type, externalMutexHandling); +PC98AudioCore::PC98AudioCore(Audio::Mixer *mixer, PC98AudioPluginDriver *driver, PC98AudioPluginDriver::EmuType type) { + _internal = PC98AudioCoreInternal::addNewRef(mixer, this, driver, type); } PC98AudioCore::~PC98AudioCore() { |