From 9a6cfc07e5ab21460cd85dbe6ac1f6de62c69524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Wed, 5 Jan 2011 15:24:50 +0100 Subject: Check elapsed time only once Task-number: QTBUG-16262 Reviewed-by: Bradley T. Hughes --- src/corelib/thread/qsemaphore.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 8e8a88a..15f45b6 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -223,8 +223,9 @@ bool QSemaphore::tryAcquire(int n, int timeout) QElapsedTimer timer; timer.start(); while (n > d->avail) { - if (timer.hasExpired(timeout) - || !d->cond.wait(locker.mutex(), timeout - timer.elapsed())) + const qint64 elapsed = timer.elapsed(); + if (timeout - elapsed > 0 + || !d->cond.wait(locker.mutex(), timeout - elapsed)) return false; } } -- cgit v0.12