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

View File

@ -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

View File

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