diff --git a/Common/ConsoleListener.cpp b/Common/ConsoleListener.cpp index 2d2851d905..4875aa2b17 100644 --- a/Common/ConsoleListener.cpp +++ b/Common/ConsoleListener.cpp @@ -15,7 +15,7 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ - +#include #include // min #include // System: To be able to add strings with "+" #include @@ -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 ConsoleListener::logPendingReadPos; +std::atomic 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); diff --git a/Common/ConsoleListener.h b/Common/ConsoleListener.h index e90654ed65..66a612a849 100644 --- a/Common/ConsoleListener.h +++ b/Common/ConsoleListener.h @@ -17,6 +17,8 @@ #pragma once +#include + #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 logPendingReadPos; + static std::atomic logPendingWritePos; int openWidth_; int openHeight_; diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index 743c01dc22..4ec83aa1da 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -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 #include #include #include @@ -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 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 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();