summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add a QMutex::isRecursive() const noexceptThiago Macieira2016-05-091-5/+8
| | | | | | | | | | | This is source- and binary-compatible, including the marking of the existing function as noexcept. [ChangeLog][QtCore][QMutex] Made the isRecursive() method be a const function so that it can be called in const QMutex objects too. Change-Id: Ifea6e497f11a461db432ffff1448bead97c08f92 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Update the Intel copyright yearThiago Macieira2016-01-211-1/+1
| | | | | | | | | Not that we require it, but since The Qt Company did it for all files they have copyright, even if they haven't touched the file in years (especially not in 2016), I'm doing the same. Change-Id: I7a9e11d7b64a4cc78e24ffff142b4c9d53039846 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Document performance of QMutexOlivier Goffart2015-11-131-0/+7
| | | | | Change-Id: I4de2fd5ba717975b5de98ffe7ca6348afbed1b2f Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Free the QFreeList object allocated memory on exitjian liang2015-09-221-4/+11
| | | | | | | | | | | | | This memory allocation was introduced in 314c83c0c2f91532654f869b7dc6af1b7e8538da. With a compiler without thread safe statics support mutex.cpp use a function named freelist() to create the global QFreeList object. it will be created when the first time it was accessed, but will never be released. This patch use Q_DESTRUCTOR_FUNCTION to delete this object. Task-number: QTBUG-48359 Change-Id: I4e4716930930aa98630101a1f96de6a7672af9cb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Do not use Q_GLOBAL_STATIC in the implementation of QMutexOlivier Goffart2015-08-131-1/+22
| | | | | | | | | | Since Q_GLOBAL_STATIC might use QMutex and cause a stack overflow. Task-number: QTBUG-47554 Change-Id: I4853c5e9b9168d4a417200e2a45a1bf9cb103a30 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Pierre Rossi <pierre.rossi@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Fix QMutex documentation saying some function are static while they are notOlivier Goffart2014-06-261-1/+1
| | | | | | | | | | | | | qdoc only see a fake QMutex class (the same as the one built in bootstrap) But that fake QMutex had static member while the normal QMutex class has non static member. QMutexLocker::mutex is also a const function in the real QMutexLocker Task-number: QTBUG-38522 Change-Id: I220434ffc6a9e990029f770e2536ecb55b4e2182 Reviewed-by: Martin Smith <martin.smith@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Use the new 3-operand testAndSet functions in QMutexThiago Macieira2014-04-051-6/+6
| | | | | | | | | This allows us to get the current value of the QMutex / QBasicMutex after the testAndSet operation failed. It saves an extra load from memory. Change-Id: I4922a8b3df15e342b177b13f56cf4f1184314520 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Doc: Adding mark-up to boolean default values.Jerome Pasion2013-10-081-3/+3
| | | | | | | | | | | | | | | | | Default values should have mark-up to denote that they are code. This commit changes: -"property is true" to "property is \c true". -"Returns true" to "Returns \c true". -"property is false" to "property is \c false". -"returns true" to "returns \c true". -"returns false" to "returns \c false". src/3rdparty and non-documentation instances were ignored. Task-number: QTBUG-33360 Change-Id: Ie87eaa57af947caa1230602b61c5c46292a4cf4e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* QMutex: fix race on 'owner' in the recursive caseMarc Mutz2013-09-211-4/+11
| | | | | | | | | | | The read from 'owner' for comparison with 'self' in QRecursiveMutexPrivate::lock() is not synchronized with the write to 'owner' in the same function further down, and neither operation is atomic. Fix by making 'owner' an atomic pointer. Change-Id: I186b88575589da0dce5827a1e17ceb4ce599ed02 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Remove use of 'register' from Qt.Stephen Kelly2013-06-171-1/+1
| | | | | | | | | | It is deprecated and clang is starting to warn about it. Patch mostly generated by clang itself, with some careful grep and sed for the platform-specific parts. Change-Id: I8058e6db0f1b41b33a9e8f17a712739159982450 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix possible race in QMutexOlivier Goffart2013-04-291-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described in the QTBUG-30872, there may be a race condition involving 3 threads fighting for a mutex. I am surprised it was not caught before despite all the Q_ASSERT and the stress test in tst_qmutex. We do not need to call store(0) because the unlocking thread will eventually remove the BigNumber flag. And perhaps it even did it already, and another thread has incremented waiters (hence the Q_ASSERT is wrong) Here is a paste of part of the description from the bug report: --- many threads, one of them is ready to release mutex, while at least two other trying to acquire it d->waiters is 0 Thread 1 release mutex in unlockInternal: if (d->waiters.fetchAndAddRelease(-QMutexPrivate::BigNumber) == 0) d->waiters is now -QMutexPrivate::BigNumber Thread 2 try to acquire mutex in lockInternal: old_waiters = d->waiters.load(); if (old_waiters == -QMutexPrivate::BigNumber) { if (d_ptr.testAndSetAcquire(d, dummyLocked())) { It acquire 'about to release mutex' by changing d to dummyLocked Thread 1 continue release procedure: d->derefWaiters(0); d->waiters is now back to 0 Thread 3 try to acquire mutex in lockInternal: while (!d->waiters.testAndSetRelaxed(old_waiters, old_waiters + 1)); d->waiters is now 1 Thread 2 continue its dummy lock: d->waiters.store(0); d->waiters is force to 0 Thread 3 continue wait procedure but it realize that mutex was already unlocked so decrease back waiters if (d != d_ptr.loadAcquire()) { if (old_waiters != QMutexPrivate::BigNumber) { d->waiters.deref(); d->waiters became negative value of -1 Neither thread need internal data so it is released back to pool The waiters counter in released internal structure is still -1 --- Change-Id: I1b22555db764482775db6e64a8c9ffa9e1ab0cf6 Task-number: QTBUG-30872 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fix some typosSergio Ahumada2012-12-211-2/+2
| | | | | Change-Id: I4e8d9bd8ea66ec810e4f1fbfd8ddbf25c4b3d980 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
* Review of documentation.Michele Caini2012-10-131-2/+10
| | | | | | | | Documentation has been updated, changes apply to Qt5 as well as Qt4. Change-Id: I562914a439d8d27dc9e6b1aa117007edce214cc6 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Add comments to document the internals of QMutexOlivier Goffart2012-09-211-2/+47
| | | | | Change-Id: Ieb5632017e5e8e09a11dc6b929efa19b4f350086 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QRecursiveMutexPrivate to qmutex.cpp and mark inlineThiago Macieira2012-09-141-2/+15
| | | | | | | | | | | | | | | | | Disassembly of the optimised code shows that the compiler was already inlining the bodies of one or both functions (since they're in the same .cpp, it's allowed to do that). However, since there was no "inline" marker, the compiler was also emitting an out-of-line copy, which wasn't used by anyone, as the class is not exported. So add the marker. To make sure that they don't get used by accident elsewhere, the class is moved to the .cpp file too. Change-Id: Iead578ec9c7d8dd6b4e6bb582ce5b829cdec5992 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* #include the qmutex_xxx.cpp at the end of qmutex.cppThiago Macieira2012-09-141-1/+10
| | | | | | | | This produces slightly better inlining results. Change-Id: Ie86471577f888cb2d9c9989306ec69ce0a296108 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Split the timed mutex lock from the non-timed lock functionsThiago Macieira2012-09-141-0/+8
| | | | | | | | | Non-timed mutex locks are by far more common, so let's try not to penalise the locking of those with code that won't get used that often. Change-Id: I37f56d6429836467fdec2e588c0fb22d914b5d75 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Make QBasicMutex be exclusively non-recursiveThiago Macieira2012-09-141-20/+40
| | | | | | | | | | | | | | | Dispatch to the recursive mutex functions from QMutex::lock, tryLock and unlock. This has the benefit that those using QBasicMutex will not go through the testing for recursive mutexes. It simplifies a little the code for those users. For the users of QMutex, the code required to perform a lock does not appear to change. Change-Id: I0ca9965e012b283c30f1fab8e9f6d9b3288c2247 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Hoist the recursive mutex check out of the inner loopThiago Macieira2012-09-141-3/+9
| | | | | | | | A non-recursive mutex doesn't suddenly become recursive, so we don't need to check it multiple times. Change-Id: Id040254b6142d320a7bd3111491082ad09968404 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Small optimisation to recursive mutexesThiago Macieira2012-08-261-2/+2
| | | | | | | | | | | A recursive mutex operates on top of a non-recursive mutex. Therefore, we can bypass the test for recursive. The end result is simply that the compiler can inline the locking and unlocking a little better inside the lock() and unlock() functions Change-Id: Ic06d1344ccd411c22cbdef74536f3a4d368d75d7 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Mark mutex locking and unlocking functions with noexceptThiago Macieira2012-08-251-9/+9
| | | | | | | | | | | | | | | | | | | | | Unlocking a mutex can never throw an exception. That doesn't make sense and our code should make sure it can't happen. Right now, provided that the system-level functions don't throw, we don't either. Locking a mutex cannot throw on Linux because we use futexes directly. A non-recursive mutex is just a futex, whereas a recursive mutex uses a mutex (a futex) to manage a lock count. However, on other platforms, due to the freelist, there can be memory allocation, which means it might throw std::bad_alloc. Not because of the freelist itself (that uses malloc and will just crash if malloc fails) but because of Q_GLOBAL_STATIC. In 5.1, the global static will be noexcept provided the type's constructor is so too (it is, in this case). Change-Id: I4c562383f48de1be7827b9afb512d73eaf0792d5 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Add \inmodule QtCore to all QtCore class doc bodiesThiago Macieira2012-08-231-0/+3
| | | | | Change-Id: I19100755c97cc155c76a859e19940e9f9222d34e Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
* Fix some spelling errorsSergio Ahumada2012-07-111-4/+4
| | | | | | Change-Id: I19d3b2e9a5180b13deb828b55195404ef20be295 Reviewed-by: Daniel Teske <daniel.teske@nokia.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QMutex: de-inline lock(), unlock(), and tryLock()Bradley T. Hughes2012-05-291-1/+12
| | | | | | | | | | | | | | See the discussion of this topic on the mailing list: http://lists.qt-project.org/pipermail/development/2012-May/003943.html The consensus is to not have these methods have inline code to actually acquire the lock (i.e. no atomic test-and-set or similar). QBasicMutex is unchanged, and continues to have inlined lock(), tryLock(), and unlock(). QMutexLocker has been changed to always call QMutex::lock() (even though the constructor takes a QBasicMutex parameter). Change-Id: Ic7d2d9d581e6b254c84fdfdd8ce6c425535a8078 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Prepare for building modular QtCore docs.Casper van Donderen2012-04-191-34/+8
| | | | | | | | | | | | This change fixes most qdoc errors in QtCore. There are about 900 left. The main thing this change does is moving documentation from qtcore from /doc/src to /src/corelib/doc. Other issues resolved are mis-use of qdoc commands. Change-Id: I002d01edfb13575e8bf27ce91596a577a92562d1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com> Reviewed-by: Jerome Pasion <jerome.pasion@nokia.com>
* Rename Q_MUTEX_LINUX to QT_LINUX_FUTEXHarald Fernengel2012-02-211-3/+3
| | | | | | | As requested by Thiago Change-Id: Ie5b00cf4e530e19d360d0bc588f0f051e04b338f Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Use standard unix mutexes on LSBHarald Fernengel2012-02-201-3/+3
| | | | | | | | LSB doesn't allow syscalls, so fall back to the normal _unix implementation Change-Id: I8aba6147da8b46e3f85b0454cf9aca219811c9fe Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Use QAtomicInt::store() instead of operator=(int)Bradley T. Hughes2011-11-011-2/+2
| | | | | | | ... since the latter is now deprecated and will be removed. Change-Id: I456c1bf93ebf119c028bc4a63f1f8a31f069b83b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
* QRecursiveMutexPrivate should not inherit from QMutexPrivateOlivier Goffart2011-10-311-18/+26
| | | | | | | | QMutexPrivate takes more memory than necessary, and also initialize platform specific ressources. Change-Id: I70be1b89b1c21499645785ae47693a6b2514e28b Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Rename QBasicMutex::d to QBasicMutex::d_ptrOlivier Goffart2011-10-311-15/+15
| | | | | | | | | Because we use d as a local variable. We used this->d to refer it, but this can be confusing to have twice the same name Change-Id: I570aa5f444ada358eb456d6b3d9b8bfa60b10bbf Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Replace implicit QAtomic* casts with explicit load()/store()Bradley T. Hughes2011-10-271-12/+12
| | | | | Change-Id: Ia7ef1a8e01001f203e409c710c977d6f4686342e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make all uses of QBasicAtomicInt and Pointer use load() and store()Bradley T. Hughes2011-10-101-4/+4
| | | | | | | | | | Change Ie3271abd1728af599f9ab17c6f4868e475f17bb6 didn't build on Mac in debug mode. This commit fixes the build. Change-Id: I925af83ea577228b60679af804aa7875a779ec3f Reviewed-on: http://codereview.qt-project.org/6331 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Make all uses of QBasicAtomicInt and Pointer use load() and store()Thiago Macieira2011-10-031-13/+10
| | | | | | | | | | | | | | Most of these changes are search-and-replace of d->ref ==, d->ref != and d->ref =. The QBasicAtomicPointer in QObjectPrivate::Connection didn't need to be basic, so I made it QAtomicPointer. Change-Id: Ie3271abd1728af599f9ab17c6f4868e475f17bb6 Reviewed-on: http://codereview.qt-project.org/5030 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* QMutex is now just a pointerOlivier Goffart2011-07-291-197/+238
| | | | | | | | | | | | | | | | | | | | | | | | | And added a POD QBasicMutex. (QBasicMutex* can safely be static_cast'ed to QMutex*) The d pointer is not anymore always a QMutexPrivate. If d == 0x0: the mutex is unlocked If d == 0x1: the mutex is locked, uncontended On linux: if d == 0x3: the mutex is locked contended, waiting on a futex If d is a pointer, it is a recursive mutex. On non-linux platforms: When a thread tries to lock a mutex for which d == 0x1, it will try to assing it a QMutexPrivated (allocated from a freelist) in order to wait for it. Change-Id: Ie1431cd9402a576fdd9a693cfd747166eebf5622 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-on: http://codereview.qt.nokia.com/2116 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
* Update licenseheader text in source files for qtbase Qt moduleJyri Tahtela2011-05-241-17/+17
| | | | | | | Updated version of LGPL and FDL licenseheaders. Apply release phase licenseheaders for all source files. Reviewed-by: Trust Me
* Initial import from the monolithic Qt.Qt by Nokia2011-04-271-0/+515
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12