Merge pull request #2528 from lioncash/volatile

EXI_DeviceEthernet: Convert a volatile bool to an atomic
This commit is contained in:
flacs 2015-06-05 18:34:15 +02:00
commit 175e0d1926
3 changed files with 13 additions and 11 deletions

View File

@ -22,7 +22,7 @@ bool CEXIETHERNET::Activate()
return false; return false;
} }
readEnabled = false; readEnabled.store(false);
INFO_LOG(SP1, "BBA initialized."); INFO_LOG(SP1, "BBA initialized.");
return true; return true;
@ -33,7 +33,7 @@ void CEXIETHERNET::Deactivate()
close(fd); close(fd);
fd = -1; fd = -1;
readEnabled = false; readEnabled.store(false);
if (readThread.joinable()) if (readThread.joinable())
readThread.join(); readThread.join();
} }
@ -83,7 +83,7 @@ static void ReadThreadHandler(CEXIETHERNET* self)
{ {
ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes); 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()); INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str());
self->mRecvBufferLength = readBytes; self->mRecvBufferLength = readBytes;
@ -103,11 +103,11 @@ bool CEXIETHERNET::RecvStart()
if (!readThread.joinable()) if (!readThread.joinable())
RecvInit(); RecvInit();
readEnabled = true; readEnabled.store(true);
return true; return true;
} }
void CEXIETHERNET::RecvStop() void CEXIETHERNET::RecvStop()
{ {
readEnabled = false; readEnabled.store(false);
} }

View File

@ -50,7 +50,7 @@ bool CEXIETHERNET::Activate()
} }
ioctl(fd, TUNSETNOCSUM, 1); ioctl(fd, TUNSETNOCSUM, 1);
readEnabled = false; readEnabled.store(false);
INFO_LOG(SP1, "BBA initialized with associated tap %s", ifr.ifr_name); INFO_LOG(SP1, "BBA initialized with associated tap %s", ifr.ifr_name);
return true; return true;
@ -66,7 +66,7 @@ void CEXIETHERNET::Deactivate()
close(fd); close(fd);
fd = -1; fd = -1;
readEnabled = false; readEnabled.store(false);
if (readThread.joinable()) if (readThread.joinable())
readThread.join(); readThread.join();
#else #else
@ -128,7 +128,7 @@ static void ReadThreadHandler(CEXIETHERNET* self)
{ {
ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes); 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()); INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str());
self->mRecvBufferLength = readBytes; self->mRecvBufferLength = readBytes;
@ -154,7 +154,7 @@ bool CEXIETHERNET::RecvStart()
if (!readThread.joinable()) if (!readThread.joinable())
RecvInit(); RecvInit();
readEnabled = true; readEnabled.store(true);
return true; return true;
#else #else
NOTIMPLEMENTED("RecvStart"); NOTIMPLEMENTED("RecvStart");
@ -165,7 +165,7 @@ bool CEXIETHERNET::RecvStart()
void CEXIETHERNET::RecvStop() void CEXIETHERNET::RecvStop()
{ {
#ifdef __linux__ #ifdef __linux__
readEnabled = false; readEnabled.store(false);
#else #else
NOTIMPLEMENTED("RecvStop"); NOTIMPLEMENTED("RecvStop");
#endif #endif

View File

@ -4,6 +4,8 @@
#pragma once #pragma once
#include <atomic>
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#endif #endif
@ -328,7 +330,7 @@ public:
#elif defined(__linux__) || defined(__APPLE__) #elif defined(__linux__) || defined(__APPLE__)
int fd; int fd;
std::thread readThread; std::thread readThread;
volatile bool readEnabled; std::atomic<bool> readEnabled;
#endif #endif
}; };