Fixed bug where flags could be permanently on or off due to multithreaded issues

This commit is contained in:
Souryo 2017-08-12 20:59:30 -04:00
parent 97c9fb88dd
commit c093de422d
2 changed files with 24 additions and 15 deletions

View file

@ -11,6 +11,7 @@ uint8_t EmulationSettings::_versionRevision = 1;
Language EmulationSettings::_displayLanguage = Language::English;
SimpleLock EmulationSettings::_lock;
uint64_t EmulationSettings::_flags = 0;
bool EmulationSettings::_audioSettingsChanged = true;

View file

@ -3,6 +3,7 @@
#include "stdafx.h"
#include "MessageManager.h"
#include "GameClient.h"
#include "../Utilities/SimpleLock.h"
enum EmulationFlags : uint64_t
{
@ -438,6 +439,8 @@ private:
static EmulatorKeyMappingSet _emulatorKeys;
static RamPowerOnState _ramPowerOnState;
static SimpleLock _lock;
public:
static uint32_t GetMesenVersion()
@ -452,35 +455,40 @@ public:
static void SetFlags(uint64_t flags)
{
_flags |= flags;
if((_flags & flags) != flags) {
//Need a lock to prevent flag changes from being ignored due to multithreaded access
LockHandler lock = _lock.AcquireSafe();
_flags |= flags;
_backgroundEnabled = !CheckFlag(EmulationFlags::DisableBackground);
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
if(flags & EmulationFlags::UseCustomVsPalette) {
UpdateCurrentPalette();
_backgroundEnabled = !CheckFlag(EmulationFlags::DisableBackground);
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
if(flags & EmulationFlags::UseCustomVsPalette) {
UpdateCurrentPalette();
}
}
}
static void SetFlagState(EmulationFlags flag, bool enabled)
{
if(enabled) {
_flags |= flag;
SetFlags(flag);
} else {
_flags &= ~flag;
ClearFlags(flag);
}
_backgroundEnabled = !CheckFlag(EmulationFlags::DisableBackground);
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
}
static void ClearFlags(uint64_t flags)
{
_flags &= ~flags;
if((_flags & flags) != 0) {
//Need a lock to prevent flag changes from being ignored due to multithreaded access
LockHandler lock = _lock.AcquireSafe();
_flags &= ~flags;
_backgroundEnabled = !CheckFlag(EmulationFlags::DisableBackground);
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
if(flags & EmulationFlags::UseCustomVsPalette) {
UpdateCurrentPalette();
_backgroundEnabled = !CheckFlag(EmulationFlags::DisableBackground);
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
if(flags & EmulationFlags::UseCustomVsPalette) {
UpdateCurrentPalette();
}
}
}