mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-11 17:18:37 +00:00
Convert atomic code in core and ConsoleListener to use C++ atomics
This commit is contained in:
parent
dc0bc0033e
commit
af18532095
@ -15,7 +15,7 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <algorithm> // min
|
||||
#include <string> // System: To be able to add strings with "+"
|
||||
#include <math.h>
|
||||
@ -49,8 +49,8 @@ HANDLE ConsoleListener::hTriggerEvent = NULL;
|
||||
CRITICAL_SECTION ConsoleListener::criticalSection;
|
||||
|
||||
char *ConsoleListener::logPending = NULL;
|
||||
volatile u32 ConsoleListener::logPendingReadPos = 0;
|
||||
volatile u32 ConsoleListener::logPendingWritePos = 0;
|
||||
std::atomic<u32> ConsoleListener::logPendingReadPos;
|
||||
std::atomic<u32> ConsoleListener::logPendingWritePos;
|
||||
#endif
|
||||
|
||||
ConsoleListener::ConsoleListener() : bHidden(true)
|
||||
@ -188,7 +188,7 @@ void ConsoleListener::Close()
|
||||
{
|
||||
if (hThread != NULL)
|
||||
{
|
||||
Common::AtomicStoreRelease(logPendingWritePos, (u32) -1);
|
||||
logPendingWritePos.store((u32)-1, std::memory_order_release);
|
||||
|
||||
SetEvent(hTriggerEvent);
|
||||
WaitForSingleObject(hThread, LOG_SHUTDOWN_DELAY_MS);
|
||||
@ -315,7 +315,7 @@ void ConsoleListener::LogWriterThread()
|
||||
WaitForSingleObject(hTriggerEvent, INFINITE);
|
||||
Sleep(LOG_LATENCY_DELAY_MS);
|
||||
|
||||
u32 logRemotePos = Common::AtomicLoadAcquire(logPendingWritePos);
|
||||
u32 logRemotePos = logPendingWritePos.load(std::memory_order_acquire);
|
||||
if (logRemotePos == (u32) -1)
|
||||
break;
|
||||
else if (logRemotePos == logPendingReadPos)
|
||||
@ -323,7 +323,7 @@ void ConsoleListener::LogWriterThread()
|
||||
else
|
||||
{
|
||||
EnterCriticalSection(&criticalSection);
|
||||
logRemotePos = Common::AtomicLoadAcquire(logPendingWritePos);
|
||||
logRemotePos = logPendingWritePos.load(std::memory_order_acquire);
|
||||
|
||||
int start = 0;
|
||||
if (logRemotePos < logPendingReadPos)
|
||||
@ -398,7 +398,7 @@ void ConsoleListener::SendToThread(LogTypes::LOG_LEVELS Level, const char *Text)
|
||||
}
|
||||
|
||||
EnterCriticalSection(&criticalSection);
|
||||
u32 logWritePos = Common::AtomicLoad(logPendingWritePos);
|
||||
u32 logWritePos = logPendingWritePos.load();
|
||||
u32 prevLogWritePos = logWritePos;
|
||||
if (logWritePos + ColorLen + Len >= LOG_PENDING_MAX)
|
||||
{
|
||||
@ -448,7 +448,7 @@ void ConsoleListener::SendToThread(LogTypes::LOG_LEVELS Level, const char *Text)
|
||||
return;
|
||||
}
|
||||
|
||||
Common::AtomicStoreRelease(logPendingWritePos, logWritePos);
|
||||
logPendingWritePos.store(logWritePos, std::memory_order::memory_order_release);
|
||||
LeaveCriticalSection(&criticalSection);
|
||||
|
||||
SetEvent(hTriggerEvent);
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "LogManager.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -44,6 +46,7 @@ public:
|
||||
|
||||
void Show(bool bShow);
|
||||
bool Hidden() const { return bHidden; }
|
||||
|
||||
private:
|
||||
#if defined(USING_WIN_UI)
|
||||
HWND hWnd;
|
||||
@ -60,8 +63,8 @@ private:
|
||||
static CRITICAL_SECTION criticalSection;
|
||||
|
||||
static char *logPending;
|
||||
static volatile u32 logPendingReadPos;
|
||||
static volatile u32 logPendingWritePos;
|
||||
static std::atomic<u32> logPendingReadPos;
|
||||
static std::atomic<u32> logPendingWritePos;
|
||||
|
||||
int openWidth_;
|
||||
int openHeight_;
|
||||
|
@ -15,7 +15,7 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
@ -76,7 +76,7 @@ Event *eventPool = 0;
|
||||
Event *eventTsPool = 0;
|
||||
int allocatedTsEvents = 0;
|
||||
// Optimization to skip MoveEvents when possible.
|
||||
volatile u32 hasTsEvents = 0;
|
||||
std::atomic<u32> hasTsEvents;
|
||||
|
||||
// Downcount has been moved to currentMIPS, to save a couple of clocks in every ARM JIT block
|
||||
// as we can already reach that structure through a register.
|
||||
@ -255,7 +255,7 @@ void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata
|
||||
tsLast->next = ne;
|
||||
tsLast = ne;
|
||||
|
||||
Common::AtomicStoreRelease(hasTsEvents, 1);
|
||||
hasTsEvents.store(1, std::memory_order::memory_order_release);
|
||||
}
|
||||
|
||||
// Same as ScheduleEvent_Threadsafe(0, ...) EXCEPT if we are already on the CPU thread
|
||||
@ -535,7 +535,7 @@ void ProcessFifoWaitEvents()
|
||||
|
||||
void MoveEvents()
|
||||
{
|
||||
Common::AtomicStoreRelease(hasTsEvents, 0);
|
||||
hasTsEvents.store(0, std::memory_order::memory_order_release);
|
||||
|
||||
std::lock_guard<std::mutex> lk(externalEventLock);
|
||||
// Move events from async queue into main queue
|
||||
@ -579,7 +579,7 @@ void Advance()
|
||||
globalTimer += cyclesExecuted;
|
||||
currentMIPS->downcount = slicelength;
|
||||
|
||||
if (Common::AtomicLoadAcquire(hasTsEvents))
|
||||
if (hasTsEvents.load(std::memory_order_acquire))
|
||||
MoveEvents();
|
||||
ProcessFifoWaitEvents();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user