Use Common::Flag and Common::Event when possible

Replaces old and simple usages of std::atomic<bool> with Common::Flag
(which was introduced after the initial usage), so it's clear that
the variable is a flag and because Common::Flag is well tested.

This also replaces the ready logic in WiimoteReal with Common::Event
since it was basically just unnecessarily reimplementing Common::Event.
This commit is contained in:
Léo Lam
2016-08-05 16:04:39 +02:00
parent c6a0e543a5
commit dca22e08eb
19 changed files with 94 additions and 132 deletions

View File

@ -9,6 +9,7 @@
#include "Common/Atomic.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Flag.h"
#include "Common/Logging/Log.h"
#include "Core/ConfigManager.h"
#include "Core/CoreTiming.h"
@ -36,8 +37,8 @@ static u16 m_bboxright;
static u16 m_bboxbottom;
static u16 m_tokenReg;
static std::atomic<bool> s_interrupt_set;
static std::atomic<bool> s_interrupt_waiting;
static Common::Flag s_interrupt_set;
static Common::Flag s_interrupt_waiting;
static bool IsOnThread()
{
@ -106,8 +107,8 @@ void Init()
fifo.bFF_LoWatermark = 0;
fifo.bFF_LoWatermarkInt = 0;
s_interrupt_set.store(false);
s_interrupt_waiting.store(false);
s_interrupt_set.Clear();
s_interrupt_waiting.Clear();
et_UpdateInterrupts = CoreTiming::RegisterEvent("CPInterrupt", UpdateInterrupts_Wrapper);
}
@ -324,18 +325,18 @@ void UpdateInterrupts(u64 userdata)
{
if (userdata)
{
s_interrupt_set.store(true);
s_interrupt_set.Set();
INFO_LOG(COMMANDPROCESSOR, "Interrupt set");
ProcessorInterface::SetInterrupt(INT_CAUSE_CP, true);
}
else
{
s_interrupt_set.store(false);
s_interrupt_set.Clear();
INFO_LOG(COMMANDPROCESSOR, "Interrupt cleared");
ProcessorInterface::SetInterrupt(INT_CAUSE_CP, false);
}
CoreTiming::ForceExceptionCheck(0);
s_interrupt_waiting.store(false);
s_interrupt_waiting.Clear();
Fifo::RunGpu();
}
@ -347,7 +348,7 @@ void UpdateInterruptsFromVideoBackend(u64 userdata)
bool IsInterruptWaiting()
{
return s_interrupt_waiting.load();
return s_interrupt_waiting.IsSet();
}
void SetCPStatusFromGPU()
@ -387,7 +388,7 @@ void SetCPStatusFromGPU()
bool interrupt = (bpInt || ovfInt || undfInt) && m_CPCtrlReg.GPReadEnable;
if (interrupt != s_interrupt_set.load() && !s_interrupt_waiting.load())
if (interrupt != s_interrupt_set.IsSet() && !s_interrupt_waiting.IsSet())
{
u64 userdata = interrupt ? 1 : 0;
if (IsOnThread())
@ -395,7 +396,7 @@ void SetCPStatusFromGPU()
if (!interrupt || bpInt || undfInt || ovfInt)
{
// Schedule the interrupt asynchronously
s_interrupt_waiting.store(true);
s_interrupt_waiting.Set();
CommandProcessor::UpdateInterruptsFromVideoBackend(userdata);
}
}
@ -418,14 +419,14 @@ void SetCPStatusFromCPU()
bool interrupt = (bpInt || ovfInt || undfInt) && m_CPCtrlReg.GPReadEnable;
if (interrupt != s_interrupt_set.load() && !s_interrupt_waiting.load())
if (interrupt != s_interrupt_set.IsSet() && !s_interrupt_waiting.IsSet())
{
u64 userdata = interrupt ? 1 : 0;
if (IsOnThread())
{
if (!interrupt || bpInt || undfInt || ovfInt)
{
s_interrupt_set.store(interrupt);
s_interrupt_set.Set(interrupt);
INFO_LOG(COMMANDPROCESSOR, "Interrupt set");
ProcessorInterface::SetInterrupt(INT_CAUSE_CP, interrupt);
}