aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItay Grudev <itay+git2020@grudev.com>2020-09-09 02:23:42 +0100
committerItay Grudev <itay+git2020@grudev.com>2020-09-09 02:23:42 +0100
commiteca580366526b52d3d597fdbd285bfcd96d429db (patch)
treef585e17e02a99e782607cee1bf56855926ec0ab4
parentRemoved extra qDebug statements (diff)
downloadsingleapplication-eca580366526b52d3d597fdbd285bfcd96d429db.tar.xz
Moved the random sleep functionality to SingleApplicationPrivate
-rw-r--r--singleapplication.cpp13
-rw-r--r--singleapplication_p.cpp18
-rw-r--r--singleapplication_p.h1
3 files changed, 20 insertions, 12 deletions
diff --git a/singleapplication.cpp b/singleapplication.cpp
index 27c0316..9b58bf8 100644
--- a/singleapplication.cpp
+++ b/singleapplication.cpp
@@ -21,14 +21,8 @@
// THE SOFTWARE.
#include <QtCore/QElapsedTimer>
-#include <QtCore/QThread>
#include <QtCore/QByteArray>
#include <QtCore/QSharedMemory>
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
-#include <QtCore/QRandomGenerator>
-#else
-#include <QtCore/QDateTime>
-#endif
#include "singleapplication.h"
#include "singleapplication_p.h"
@@ -119,12 +113,7 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
qDebug() << "SingleApplication: Unable to unlock memory for random wait.";
qDebug() << d->memory->errorString();
}
-#if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 )
- QThread::sleep( QRandomGenerator::global()->bounded( 8u, 18u ));
-#else
- qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max() );
- QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( qrand() ) / RAND_MAX * 10 ));
-#endif
+ d->randomSleep();
if( ! d->memory->lock() ){
qCritical() << "SingleApplication: Unable to lock memory after random wait.";
abortSafely();
diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp
index a826e8a..c453315 100644
--- a/singleapplication_p.cpp
+++ b/singleapplication_p.cpp
@@ -33,12 +33,20 @@
#include <cstddef>
#include <QtCore/QDir>
+#include <QtCore/QThread>
#include <QtCore/QByteArray>
#include <QtCore/QDataStream>
+#include <QtCore/QElapsedTimer>
#include <QtCore/QCryptographicHash>
#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
+#include <QtCore/QRandomGenerator>
+#else
+#include <QtCore/QDateTime>
+#endif
+
#include "singleapplication.h"
#include "singleapplication_p.h"
@@ -434,3 +442,13 @@ void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedS
if( closedSocket->bytesAvailable() > 0 )
Q_EMIT slotDataAvailable( closedSocket, instanceId );
}
+
+void SingleApplicationPrivate::randomSleep()
+{
+#if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 )
+ QThread::msleep( QRandomGenerator::global()->bounded( 8u, 18u ));
+#else
+ qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max() );
+ QThread::msleep( 8 + static_cast <unsigned long>( static_cast <float>( qrand() ) / RAND_MAX * 10 ));
+#endif
+}
diff --git a/singleapplication_p.h b/singleapplication_p.h
index 9358c4b..6ecf9a6 100644
--- a/singleapplication_p.h
+++ b/singleapplication_p.h
@@ -81,6 +81,7 @@ public:
QString primaryUser();
void readInitMessageHeader(QLocalSocket *socket);
void readInitMessageBody(QLocalSocket *socket);
+ void randomSleep();
SingleApplication *q_ptr;
QSharedMemory *memory;