diff --git a/Source/Core/Core/HW/BBA-TAP/TAP_Apple.cpp b/Source/Core/Core/HW/BBA-TAP/TAP_Apple.cpp index 22b98e8cdb..a990e985bc 100644 --- a/Source/Core/Core/HW/BBA-TAP/TAP_Apple.cpp +++ b/Source/Core/Core/HW/BBA-TAP/TAP_Apple.cpp @@ -22,7 +22,7 @@ bool CEXIETHERNET::Activate() return false; } - readEnabled = false; + readEnabled.store(false); INFO_LOG(SP1, "BBA initialized."); return true; @@ -33,7 +33,7 @@ void CEXIETHERNET::Deactivate() close(fd); fd = -1; - readEnabled = false; + readEnabled.store(false); if (readThread.joinable()) readThread.join(); } @@ -83,7 +83,7 @@ static void ReadThreadHandler(CEXIETHERNET* self) { ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes); } - else if (self->readEnabled) + else if (self->readEnabled.load()) { INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str()); self->mRecvBufferLength = readBytes; @@ -103,11 +103,11 @@ bool CEXIETHERNET::RecvStart() if (!readThread.joinable()) RecvInit(); - readEnabled = true; + readEnabled.store(true); return true; } void CEXIETHERNET::RecvStop() { - readEnabled = false; + readEnabled.store(false); } diff --git a/Source/Core/Core/HW/BBA-TAP/TAP_Unix.cpp b/Source/Core/Core/HW/BBA-TAP/TAP_Unix.cpp index ac3eecf4a1..be16f437eb 100644 --- a/Source/Core/Core/HW/BBA-TAP/TAP_Unix.cpp +++ b/Source/Core/Core/HW/BBA-TAP/TAP_Unix.cpp @@ -50,7 +50,7 @@ bool CEXIETHERNET::Activate() } ioctl(fd, TUNSETNOCSUM, 1); - readEnabled = false; + readEnabled.store(false); INFO_LOG(SP1, "BBA initialized with associated tap %s", ifr.ifr_name); return true; @@ -66,7 +66,7 @@ void CEXIETHERNET::Deactivate() close(fd); fd = -1; - readEnabled = false; + readEnabled.store(false); if (readThread.joinable()) readThread.join(); #else @@ -128,7 +128,7 @@ static void ReadThreadHandler(CEXIETHERNET* self) { ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes); } - else if (self->readEnabled) + else if (self->readEnabled.load()) { INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str()); self->mRecvBufferLength = readBytes; @@ -154,7 +154,7 @@ bool CEXIETHERNET::RecvStart() if (!readThread.joinable()) RecvInit(); - readEnabled = true; + readEnabled.store(true); return true; #else NOTIMPLEMENTED("RecvStart"); @@ -165,7 +165,7 @@ bool CEXIETHERNET::RecvStart() void CEXIETHERNET::RecvStop() { #ifdef __linux__ - readEnabled = false; + readEnabled.store(false); #else NOTIMPLEMENTED("RecvStop"); #endif diff --git a/Source/Core/Core/HW/EXI_DeviceEthernet.h b/Source/Core/Core/HW/EXI_DeviceEthernet.h index 04376bccbd..db5e92bc43 100644 --- a/Source/Core/Core/HW/EXI_DeviceEthernet.h +++ b/Source/Core/Core/HW/EXI_DeviceEthernet.h @@ -4,6 +4,8 @@ #pragma once +#include + #ifdef _WIN32 #include #endif @@ -328,7 +330,7 @@ public: #elif defined(__linux__) || defined(__APPLE__) int fd; std::thread readThread; - volatile bool readEnabled; + std::atomic readEnabled; #endif };