diff options
| author | Seth Riley <17361645+Qudix@users.noreply.github.com> | 2020-11-06 12:02:43 -0600 |
|---|---|---|
| committer | Seth Riley <17361645+Qudix@users.noreply.github.com> | 2020-11-06 12:02:43 -0600 |
| commit | ed1085d5673e0d307a6172eaaa1be1e9d70e2234 (patch) | |
| tree | 1e068a2f08e106c8ce15be7034f19336836cc17a /src/singleinstance.cpp | |
| parent | 34e1d05c28bf4676ed8d3e97e969187a05d215b6 (diff) | |
| parent | b909677c3fc6a7b7a1993d341a2bd420715e292a (diff) | |
Merge branch 'master' of https://github.com/ModOrganizer2/modorganizer into master
Diffstat (limited to 'src/singleinstance.cpp')
| -rw-r--r-- | src/singleinstance.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index aa62d40a..bd7ccc43 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -28,33 +28,28 @@ static const int s_Timeout = 5000; using MOBase::reportError;
-SingleInstance::SingleInstance(bool forcePrimary, QObject *parent) :
- QObject(parent), m_PrimaryInstance(false)
+SingleInstance::SingleInstance(bool allowMultiple, QObject *parent) :
+ QObject(parent), m_Ephemeral(false), m_OwnsSM(false)
{
m_SharedMem.setKey(s_Key);
+
if (!m_SharedMem.create(1)) {
- if (forcePrimary) {
- while (m_SharedMem.error() == QSharedMemory::AlreadyExists) {
- Sleep(500);
- if (m_SharedMem.create(1)) {
- m_PrimaryInstance = true;
- break;
- }
+ if (m_SharedMem.error() == QSharedMemory::AlreadyExists) {
+ if (!allowMultiple) {
+ m_SharedMem.attach();
+ m_Ephemeral = true;
}
}
- if (m_SharedMem.error() == QSharedMemory::AlreadyExists) {
- m_SharedMem.attach();
- m_PrimaryInstance = false;
- }
if ((m_SharedMem.error() != QSharedMemory::NoError) &&
(m_SharedMem.error() != QSharedMemory::AlreadyExists)) {
throw MOBase::MyException(tr("SHM error: %1").arg(m_SharedMem.errorString()));
}
} else {
- m_PrimaryInstance = true;
+ m_OwnsSM = true;
}
- if (m_PrimaryInstance) {
+
+ if (m_OwnsSM) {
connect(&m_Server, SIGNAL(newConnection()), this, SLOT(receiveMessage()), Qt::QueuedConnection);
// has to be called before listen
m_Server.setSocketOptions(QLocalServer::WorldAccessOption);
@@ -65,7 +60,7 @@ SingleInstance::SingleInstance(bool forcePrimary, QObject *parent) : void SingleInstance::sendMessage(const QString &message)
{
- if (m_PrimaryInstance) {
+ if (m_OwnsSM) {
// nobody there to receive the message
return;
}
|
