diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-10-01 07:50:22 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-12-20 15:49:51 (GMT) |
commit | 3b6a84de5c5ed2e1970ad2b396292babb9173227 (patch) | |
tree | 897d4451642314f832f0ebdd3c6d408e446d44e2 /src/corelib/thread/qmutex_win.cpp | |
parent | 8a7b5aca7b6575013a4e4ee9b99808d25edf6fdf (diff) | |
download | Qt-3b6a84de5c5ed2e1970ad2b396292babb9173227.zip Qt-3b6a84de5c5ed2e1970ad2b396292babb9173227.tar.gz Qt-3b6a84de5c5ed2e1970ad2b396292babb9173227.tar.bz2 |
Optimize adaptive spinning mutex code
Change the adaptive spinning code to be elapsed time based instead of
iteration based. The new approach will quickly reduce the amount of
allowed spinning time when it detects that lock contention is resolved
by waiting instead of spinning. We get better results by dynamically
adjusting for elapsed running time instead of trying to fine tune
iteration counts that won't work for all CPU types, speeds, etc.
From observation, lock performance suffers if the spin time is higher
than the minimum wait time. Because of this, QMutex never increases the
spin time, it only reduces the spin time to the minimum observed wait time.
For very long wait times, we disable spinning completely (and always resolve
contention by waiting).
Use QThread::yieldCurrentThread() when spinning on a contended mutex. Comment
from the code: be a good citizen... yielding lets something else run if
there is something to run, but may also relieve memory pressure if not.
Reviewed-by: joao
Diffstat (limited to 'src/corelib/thread/qmutex_win.cpp')
-rw-r--r-- | src/corelib/thread/qmutex_win.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/thread/qmutex_win.cpp b/src/corelib/thread/qmutex_win.cpp index c278f04..89e8b87 100644 --- a/src/corelib/thread/qmutex_win.cpp +++ b/src/corelib/thread/qmutex_win.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE QMutexPrivate::QMutexPrivate(QMutex::RecursionMode mode) - : QMutexData(mode), lastSpinCount(0), owner(0), count(0) + : QMutexData(mode), maximumSpinTime(MaximumSpinTimeThreshold), owner(0), count(0) { event = CreateEvent(0, FALSE, FALSE, 0); if (!event) |