QLockFile::tryLock: prevent over-sleeping in certain cases
The sleep time increases exponentially, but we never checked whether the time to sleep was less than the remaining time. For example, if timeout was 4000 ms on entry, we'd progressively sleep 100 ms, 200, 400, 800, 1600 ms. At this point, the accummulated sleep time would be 3100 ms and the next sleep should be no more than 900 ms. Prior to this change, the tryLock() would then proceed to sleep 3200 ms, for a total wait time of 6300 ms, or 57.5% above the timeout provided by the user. Change-Id: Ifc295639c8cf4ddcaa69fffd146f7586a7ee95e4 Reviewed-by: David Faure <david.faure@kdab.com>bb10
parent
eebdb16c63
commit
84830fc07d
|
|
@ -233,8 +233,13 @@ bool QLockFile::tryLock(int timeout)
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (timer.hasExpired())
|
||||
|
||||
int remainingTime = timer.remainingTime();
|
||||
if (remainingTime == 0)
|
||||
return false;
|
||||
else if (uint(sleepTime) > uint(remainingTime))
|
||||
sleepTime = remainingTime;
|
||||
|
||||
QThread::msleep(sleepTime);
|
||||
if (sleepTime < 5 * 1000)
|
||||
sleepTime *= 2;
|
||||
|
|
|
|||
Loading…
Reference in New Issue