-
Notifications
You must be signed in to change notification settings - Fork 3
/
RunGuard.h
41 lines (31 loc) · 854 Bytes
/
RunGuard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
--------------------------------------------------------------------------------
- Module : runGuard.h
- Description : This file for usage with QT makes sure only a single
- instance of the program is run.
- Author : SaZ from Stackoverflow
- Tim Zaman, 18-FEB-2016
--------------------------------------------------------------------------------
*/
#ifndef RUNGUARD_H
#define RUNGUARD_H
#include <QObject>
#include <QSharedMemory>
#include <QSystemSemaphore>
class RunGuard
{
public:
RunGuard( const QString& key );
~RunGuard();
bool isAnotherRunning();
bool tryToRun();
void release();
private:
const QString key;
const QString memLockKey;
const QString sharedmemKey;
QSharedMemory sharedMem;
QSystemSemaphore memLock;
Q_DISABLE_COPY( RunGuard )
};
#endif // RUNGUARD_H