From 87bab705ded31559941020d3c500f43f571f9c16 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Fri, 1 Oct 2010 09:45:42 +0200 Subject: Disable spinning under lock contention on single CPU machines Spinning is just wasted time on these systems. Reviewed-by: joao --- src/corelib/thread/qmutex.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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(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; -- cgit v0.12