Skip to content

Commit

Permalink
Removed QMutex for thread safe behaviour and support for multiple Sin…
Browse files Browse the repository at this point in the history
…gleApplication instances

Problem raised by @retmas in #24
  • Loading branch information
itay-grudev committed Apr 23, 2017
1 parent eee5d95 commit c2a6fac
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
17 changes: 1 addition & 16 deletions singleapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ void SingleApplicationPrivate::connectToPrimary( int msecs, char connectionType
#ifdef Q_OS_UNIX
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
// QSharedMemory block is deleted even if the process crashes
signal( SIGHUP, SingleApplicationPrivate::terminate ); // 1
Expand All @@ -249,15 +240,9 @@ void SingleApplicationPrivate::connectToPrimary( int msecs, char connectionType

void SingleApplicationPrivate::terminate( int signum )
{
while( ! sharedMem.empty() ) {
delete sharedMem.back();
sharedMem.pop_back();
}
delete ((SingleApplication*)QApplication::instance())->d_ptr;
::exit( 128 + signum );
}

QList<SingleApplicationPrivate*> SingleApplicationPrivate::sharedMem;
QMutex SingleApplicationPrivate::sharedMemMutex;
#endif

/**
Expand Down
3 changes: 0 additions & 3 deletions singleapplication_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef SINGLEAPPLICATION_P_H
#define SINGLEAPPLICATION_P_H

#include <QtCore/QMutex>
#include <QtCore/QSharedMemory>
#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>
Expand All @@ -59,8 +58,6 @@ Q_OBJECT
#ifdef Q_OS_UNIX
void crashHandler();
static void terminate( int signum );
static QList<SingleApplicationPrivate*> sharedMem;
static QMutex sharedMemMutex;
#endif

QSharedMemory *memory;
Expand Down

0 comments on commit c2a6fac

Please sign in to comment.