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

@ -19,7 +19,7 @@ AsyncRequests::AsyncRequests() : m_enable(false), m_passthrough(true)
void AsyncRequests::PullEventsInternal()
{
std::unique_lock<std::mutex> lock(m_mutex);
m_empty.store(true);
m_empty.Set();
while (!m_queue.empty())
{
@ -76,7 +76,7 @@ void AsyncRequests::PushEvent(const AsyncRequests::Event& event, bool blocking)
return;
}
m_empty.store(false);
m_empty.Clear();
m_wake_me_up_again |= blocking;
if (!m_enable)

View File

@ -4,13 +4,13 @@
#pragma once
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/Flag.h"
struct EfbPokeData;
@ -70,7 +70,7 @@ public:
void PullEvents()
{
if (!m_empty.load())
if (!m_empty.IsSet())
PullEventsInternal();
}
void PushEvent(const Event& event, bool blocking = false);
@ -84,7 +84,7 @@ private:
static AsyncRequests s_singleton;
std::atomic<bool> m_empty;
Common::Flag m_empty;
std::queue<Event> m_queue;
std::mutex m_mutex;
std::condition_variable m_cond;

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);
}

View File

@ -36,7 +36,7 @@ static bool s_skip_current_frame = false;
static Common::BlockingLoop s_gpu_mainloop;
static std::atomic<bool> s_emu_running_state;
static Common::Flag s_emu_running_state;
// Most of this array is unlikely to be faulted in...
static u8 s_fifo_aux_data[FIFO_SIZE];
@ -147,13 +147,13 @@ void ExitGpuLoop()
FlushGpu();
// Terminate GPU thread loop
s_emu_running_state.store(true);
s_emu_running_state.Set();
s_gpu_mainloop.Stop(false);
}
void EmulatorState(bool running)
{
s_emu_running_state.store(running);
s_emu_running_state.Set(running);
if (running)
s_gpu_mainloop.Wakeup();
else
@ -307,7 +307,7 @@ void RunGpuLoop()
g_video_backend->PeekMessages();
// Do nothing while paused
if (!s_emu_running_state.load())
if (!s_emu_running_state.IsSet())
return;
if (s_use_deterministic_gpu_thread)