AbstractTool optimization: Only wait for the *remaining* delay time, rather than the complete delay time.

This commit is contained in:
LoRd_MuldeR 2014-12-05 23:01:38 +01:00
parent 67429fbada
commit 1da760139a

View File

@ -53,7 +53,7 @@ QMutex AbstractTool::s_startProcessMutex;
/* /*
* Const * 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 static const quint64 START_DELAY_NANO = quint64(START_DELAY) * 10000ui64; //in 100-nanosecond intervals
/* /*
@ -85,11 +85,14 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
{ {
QMutexLocker lock(&s_startProcessMutex); 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(); lock.unlock();
MUtils::OS::sleep_ms(START_DELAY); MUtils::OS::sleep_ms(size_t((expectedFileTime - currentFileTime) / 10000ui64) + 1U);
lock.relock(); lock.relock();
currentFileTime = MUtils::OS::current_file_time();
} }
emit messageLogged(commandline2string(program, args) + "\n"); emit messageLogged(commandline2string(program, args) + "\n");