mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
34 lines
736 B
C++
34 lines
736 B
C++
#ifndef VSINGLEINSTANCEGUARD_H
|
|
#define VSINGLEINSTANCEGUARD_H
|
|
|
|
#include <QString>
|
|
#include <QSharedMemory>
|
|
#include <QSystemSemaphore>
|
|
|
|
class VSingleInstanceGuard
|
|
{
|
|
public:
|
|
VSingleInstanceGuard();
|
|
~VSingleInstanceGuard();
|
|
bool tryRun();
|
|
|
|
private:
|
|
void detachMemory();
|
|
bool tryAttach();
|
|
|
|
struct SharedStruct {
|
|
// A magic number to identify if this struct is initialized
|
|
int m_magic;
|
|
// If it is 1, then another instance ask this instance to show itself
|
|
int m_activeRequest;
|
|
};
|
|
|
|
static const QString m_memKey;
|
|
static const QString m_semKey;
|
|
static const int m_magic;
|
|
QSharedMemory m_sharedMemory;
|
|
QSystemSemaphore m_sem;
|
|
};
|
|
|
|
#endif // VSINGLEINSTANCEGUARD_H
|