blob: c8878fec7bfb4d5a69501e87a7fad17e34a450d8 [file] [log] [blame]
Andreas Traczyk45f56c92019-01-06 10:04:44 -05001// From: https://stackoverflow.com/a/28172162
2
3#pragma once
4
5#include <QObject>
6#include <QSharedMemory>
7#include <QSystemSemaphore>
8
9class RunGuard
10{
11
12public:
13 RunGuard(const QString& key);
14 ~RunGuard();
15
16 bool isAnotherRunning();
17 bool tryToRun();
18 void release();
19
20private:
21 const QString key;
22 const QString memLockKey;
23 const QString sharedmemKey;
24
25 QSharedMemory sharedMem;
26 QSystemSemaphore memLock;
27
28 Q_DISABLE_COPY(RunGuard)
29};