diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-10-01 07:45:42 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-12-20 15:49:42 (GMT) |
commit | 87bab705ded31559941020d3c500f43f571f9c16 (patch) | |
tree | 9a6c8b842852528adf10b9b6a454753b52e303d6 /src/corelib/thread/qmutex.cpp | |
parent | feb0b0cd47808a77a048c6a13686d39a0540a488 (diff) | |
download | Qt-87bab705ded31559941020d3c500f43f571f9c16.zip Qt-87bab705ded31559941020d3c500f43f571f9c16.tar.gz Qt-87bab705ded31559941020d3c500f43f571f9c16.tar.bz2 |
Disable spinning under lock contention on single CPU machines
Spinning is just wasted time on these systems.
Reviewed-by: joao
Diffstat (limited to 'src/corelib/thread/qmutex.cpp')
-rw-r--r-- | src/corelib/thread/qmutex.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 19e2457..54b3ed4 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -429,6 +429,16 @@ void QMutex::unlock() void QMutex::lockInternal() { QMutexPrivate *d = static_cast<QMutexPrivate *>(this->d); + + if (QThread::idealThreadCount() == 1) { + // don't spin on single cpu machines + bool isLocked = d->wait(); + Q_ASSERT_X(isLocked, "QMutex::lock", + "Internal error, infinite wait has timed out."); + Q_UNUSED(isLocked); + return; + } + int spinCount = 0; int lastSpinCount = d->lastSpinCount; |