mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #4679
anthony.bilinski (1): fix(IPC): don't double lock shared memory
This commit is contained in:
commit
ab12555935
30
src/ipc.cpp
30
src/ipc.cpp
|
@ -81,11 +81,13 @@ IPC::IPC(uint32_t profileId)
|
||||||
|
|
||||||
IPC::~IPC()
|
IPC::~IPC()
|
||||||
{
|
{
|
||||||
if (isCurrentOwner()) {
|
|
||||||
if (globalMemory.lock()) {
|
if (globalMemory.lock()) {
|
||||||
|
if (isCurrentOwnerNoLock()) {
|
||||||
global()->globalId = 0;
|
global()->globalId = 0;
|
||||||
globalMemory.unlock();
|
|
||||||
}
|
}
|
||||||
|
globalMemory.unlock();
|
||||||
|
} else {
|
||||||
|
qWarning() << "Failed to lock in ~IPC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,13 +137,7 @@ time_t IPC::postEvent(const QString& name, const QByteArray& data, uint32_t dest
|
||||||
bool IPC::isCurrentOwner()
|
bool IPC::isCurrentOwner()
|
||||||
{
|
{
|
||||||
if (globalMemory.lock()) {
|
if (globalMemory.lock()) {
|
||||||
void* data = globalMemory.data();
|
const bool isOwner = isCurrentOwnerNoLock();
|
||||||
if (!data) {
|
|
||||||
qWarning() << "isCurrentOwner failed to access the memory, returning false";
|
|
||||||
globalMemory.unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool isOwner = ((*(uint64_t*)data) == globalId);
|
|
||||||
globalMemory.unlock();
|
globalMemory.unlock();
|
||||||
return isOwner;
|
return isOwner;
|
||||||
} else {
|
} else {
|
||||||
|
@ -216,7 +212,7 @@ IPC::IPCEvent* IPC::fetchEvent()
|
||||||
memset(evt, 0, sizeof(IPCEvent));
|
memset(evt, 0, sizeof(IPCEvent));
|
||||||
|
|
||||||
if (evt->posted && !evt->processed && evt->sender != getpid()
|
if (evt->posted && !evt->processed && evt->sender != getpid()
|
||||||
&& (evt->dest == profileId || (evt->dest == 0 && isCurrentOwner())))
|
&& (evt->dest == profileId || (evt->dest == 0 && isCurrentOwnerNoLock())))
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +277,20 @@ void IPC::processEvents()
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Only called when global memory IS LOCKED.
|
||||||
|
* @return true if owner, false if not owner or if error
|
||||||
|
*/
|
||||||
|
bool IPC::isCurrentOwnerNoLock()
|
||||||
|
{
|
||||||
|
const void* const data = globalMemory.data();
|
||||||
|
if (!data) {
|
||||||
|
qWarning() << "isCurrentOwnerNoLock failed to access the memory, returning false";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (*static_cast<const uint64_t*>(data) == globalId);
|
||||||
|
}
|
||||||
|
|
||||||
IPC::IPCMemory* IPC::global()
|
IPC::IPCMemory* IPC::global()
|
||||||
{
|
{
|
||||||
return static_cast<IPCMemory*>(globalMemory.data());
|
return static_cast<IPCMemory*>(globalMemory.data());
|
||||||
|
|
|
@ -82,6 +82,7 @@ private:
|
||||||
bool runEventHandler(IPCEventHandler handler, const QByteArray& arg);
|
bool runEventHandler(IPCEventHandler handler, const QByteArray& arg);
|
||||||
IPCEvent* fetchEvent();
|
IPCEvent* fetchEvent();
|
||||||
void processEvents();
|
void processEvents();
|
||||||
|
bool isCurrentOwnerNoLock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user