Switch to using QAtomicInc instead of "volatile" flags in more places.

This commit is contained in:
LoRd_MuldeR 2017-04-20 22:59:57 +02:00
parent 6d6c969339
commit c3dab4d642
2 changed files with 5 additions and 8 deletions

View File

@ -53,19 +53,18 @@ IPCSendThread::IPCSendThread(MUtils::IPCChannel *const ipc, const quint32 &comma
: :
m_ipc(ipc), m_command(command), m_message(message) m_ipc(ipc), m_command(command), m_message(message)
{ {
m_result = false;
} }
void IPCSendThread::run(void) void IPCSendThread::run(void)
{ {
try try
{ {
m_result = m_ipc->send(m_command, 0, QStringList() << m_message); m_result.fetchAndStoreOrdered(m_ipc->send(m_command, 0, QStringList() << m_message) ? 1 : 0);
} }
catch(...) catch(...)
{ {
qWarning("Exception in IPC receive thread!"); qWarning("Exception in IPC receive thread!");
m_result = false; m_result.fetchAndStoreOrdered(0);
} }
} }
@ -78,7 +77,6 @@ IPCReceiveThread::IPCReceiveThread(MUtils::IPCChannel *const ipc)
: :
m_ipc(ipc) m_ipc(ipc)
{ {
m_stopped = false;
} }
void IPCReceiveThread::run(void) void IPCReceiveThread::run(void)
@ -111,9 +109,8 @@ void IPCReceiveThread::receiveLoop(void)
void IPCReceiveThread::stop(void) void IPCReceiveThread::stop(void)
{ {
if(!m_stopped) if(m_stopped.testAndSetOrdered(0, 1))
{ {
m_stopped = true;
IPC::sendAsync(m_ipc, IPC::COMMAND_NONE, "exit"); IPC::sendAsync(m_ipc, IPC::COMMAND_NONE, "exit");
} }
} }

View File

@ -41,7 +41,7 @@ public:
virtual void run(void); virtual void run(void);
private: private:
volatile bool m_result; QAtomicInt m_result;
MUtils::IPCChannel *const m_ipc; MUtils::IPCChannel *const m_ipc;
const quint32 m_command; const quint32 m_command;
const QString m_message; const QString m_message;
@ -63,7 +63,7 @@ signals:
private: private:
void receiveLoop(void); void receiveLoop(void);
volatile bool m_stopped; QAtomicInt m_stopped;
MUtils::IPCChannel *const m_ipc; MUtils::IPCChannel *const m_ipc;
}; };