From 1da760139ae5ec661146db23403c1ad088105a81 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 5 Dec 2014 23:01:38 +0100 Subject: [PATCH] AbstractTool optimization: Only wait for the *remaining* delay time, rather than the complete delay time. --- src/Tool_Abstract.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index 7d7c96ca..a68d629b 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -53,7 +53,7 @@ QMutex AbstractTool::s_startProcessMutex; /* * Const */ -static const unsigned int START_DELAY = 50U; //in milliseconds +static const unsigned int START_DELAY = 100U; //in milliseconds static const quint64 START_DELAY_NANO = quint64(START_DELAY) * 10000ui64; //in 100-nanosecond intervals /* @@ -84,12 +84,15 @@ AbstractTool::~AbstractTool(void) bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args) { QMutexLocker lock(&s_startProcessMutex); - - while(MUtils::OS::current_file_time() <= s_startProcessTimer) + + quint64 currentFileTime = MUtils::OS::current_file_time(); + while(currentFileTime < s_startProcessTimer) { + const quint64 expectedFileTime = s_startProcessTimer; lock.unlock(); - MUtils::OS::sleep_ms(START_DELAY); + MUtils::OS::sleep_ms(size_t((expectedFileTime - currentFileTime) / 10000ui64) + 1U); lock.relock(); + currentFileTime = MUtils::OS::current_file_time(); } emit messageLogged(commandline2string(program, args) + "\n");