mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-01-15 17:02:06 +08:00
Removed QMutex for thread safe behaviour and support for multiple SingleApplication instances
Problem raised by @retmas in #24
This commit is contained in:
parent
eee5d9544b
commit
c2a6faca68
@ -220,15 +220,6 @@ void SingleApplicationPrivate::connectToPrimary( int msecs, char connectionType
|
|||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
void SingleApplicationPrivate::crashHandler()
|
void SingleApplicationPrivate::crashHandler()
|
||||||
{
|
{
|
||||||
// This guarantees the program will work even with multiple
|
|
||||||
// instances of SingleApplication in different threads.
|
|
||||||
// Which in my opinion is idiotic, but lets handle that too.
|
|
||||||
{
|
|
||||||
sharedMemMutex.lock();
|
|
||||||
sharedMem.append( this );
|
|
||||||
sharedMemMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle any further termination signals to ensure the
|
// Handle any further termination signals to ensure the
|
||||||
// QSharedMemory block is deleted even if the process crashes
|
// QSharedMemory block is deleted even if the process crashes
|
||||||
signal( SIGHUP, SingleApplicationPrivate::terminate ); // 1
|
signal( SIGHUP, SingleApplicationPrivate::terminate ); // 1
|
||||||
@ -249,15 +240,9 @@ void SingleApplicationPrivate::connectToPrimary( int msecs, char connectionType
|
|||||||
|
|
||||||
void SingleApplicationPrivate::terminate( int signum )
|
void SingleApplicationPrivate::terminate( int signum )
|
||||||
{
|
{
|
||||||
while( ! sharedMem.empty() ) {
|
delete ((SingleApplication*)QApplication::instance())->d_ptr;
|
||||||
delete sharedMem.back();
|
|
||||||
sharedMem.pop_back();
|
|
||||||
}
|
|
||||||
::exit( 128 + signum );
|
::exit( 128 + signum );
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<SingleApplicationPrivate*> SingleApplicationPrivate::sharedMem;
|
|
||||||
QMutex SingleApplicationPrivate::sharedMemMutex;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#ifndef SINGLEAPPLICATION_P_H
|
#ifndef SINGLEAPPLICATION_P_H
|
||||||
#define SINGLEAPPLICATION_P_H
|
#define SINGLEAPPLICATION_P_H
|
||||||
|
|
||||||
#include <QtCore/QMutex>
|
|
||||||
#include <QtCore/QSharedMemory>
|
#include <QtCore/QSharedMemory>
|
||||||
#include <QtNetwork/QLocalServer>
|
#include <QtNetwork/QLocalServer>
|
||||||
#include <QtNetwork/QLocalSocket>
|
#include <QtNetwork/QLocalSocket>
|
||||||
@ -59,8 +58,6 @@ public:
|
|||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
void crashHandler();
|
void crashHandler();
|
||||||
static void terminate( int signum );
|
static void terminate( int signum );
|
||||||
static QList<SingleApplicationPrivate*> sharedMem;
|
|
||||||
static QMutex sharedMemMutex;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QSharedMemory *memory;
|
QSharedMemory *memory;
|
||||||
|
Loading…
Reference in New Issue
Block a user