diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-09-16 08:50:25 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-12-20 15:49:36 (GMT) |
commit | d9e35493d494df60d771a928a8d0dbde2b66906e (patch) | |
tree | e7a9922f2b2ce9deba4e4a8a08bda038a51b1310 /src/corelib/thread/qmutex_win.cpp | |
parent | 2d87a865b26250dcecbcf73178f8091e0724106d (diff) | |
download | Qt-d9e35493d494df60d771a928a8d0dbde2b66906e.zip Qt-d9e35493d494df60d771a928a8d0dbde2b66906e.tar.gz Qt-d9e35493d494df60d771a928a8d0dbde2b66906e.tar.bz2 |
Move contender count maintenance to QMutexPrivate
Make the cross-platform implementation of QMutex in qmutex.cpp only use
testAndSetAcquire(0, 1) and testAndSetRelease(1, 0) like in the new inline
functions in qmutex.h
This will allow us to open up for more platform-specific optimizations to
improve performance of contended QMutexes.
Reviewed-by: joao
Diffstat (limited to 'src/corelib/thread/qmutex_win.cpp')
-rw-r--r-- | src/corelib/thread/qmutex_win.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/thread/qmutex_win.cpp b/src/corelib/thread/qmutex_win.cpp index a810000..c278f04 100644 --- a/src/corelib/thread/qmutex_win.cpp +++ b/src/corelib/thread/qmutex_win.cpp @@ -60,7 +60,13 @@ QMutexPrivate::~QMutexPrivate() bool QMutexPrivate::wait(int timeout) { - return WaitForSingleObject(event, timeout < 0 ? INFINITE : timeout) == WAIT_OBJECT_0; + if (contenders.fetchAndAddAcquire(1) == 0) { + // lock acquired without waiting + return true; + } + bool returnValue = (WaitForSingleObject(event, timeout < 0 ? INFINITE : timeout) == WAIT_OBJECT_0); + contenders.deref(); + return returnValue; } void QMutexPrivate::wakeUp() |