summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex_linux.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* 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>
* Move the creation of QElapsedTimer out of the inner function in QMutexThiago Macieira2013-08-271-21/+5
| | | | | | | Makes it possible for QElapsedTimer to be non-POD. Change-Id: I5ffc59c7a93c187a4a814e6959f8383fa8d4cc44 Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
* 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 QMutex::tryLock with negative valuesThiago Macieira2012-12-231-3/+2
| | | | | | | | | | | | The Linux futex implementation had a Q_ASSERT for positive values, but the documentation says that negative values should be interpreted as infinite (equal to lock()). Test that too. Change-Id: I2f96a502d672732781e88e49797756ca9a809121 Reviewed-by: David Faure (KDE) <faure@kde.org> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Fix QMutex::tryLock timeout computation on LinuxOlivier Goffart2012-11-161-2/+2
| | | | | | | | | | | The timeout is in millisecond. So we just need to divide by 1000 to get the number of seconds Regression introduced in f587e8f4fd670f11fa1e878c1015d7241033559a Reported in the comments of QTBUG-24795 Change-Id: Id16e05e7d04d33605860926f7516d14cdefd6a36 Reviewed-by: Thiago Macieira <thiago.macieira@intel.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>
* Use storeRelease to unlock a mutex instead of fetchAndStoreReleaseThiago Macieira2012-09-141-1/+1
| | | | | | | | We're not checking the result anyway, so use a simpler operation. Change-Id: I8c2db35be86660b29d81dd97ce3e269de55a37df Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Avoid calling QElapsedTimer::nsecsElapsed before the first futex sleepThiago Macieira2012-09-141-4/+8
| | | | | | | | | | The first time we're going to sleep, the timeout should be exactly the value that was passed by the user. We don't need to calculate the time elapsed between start() and a few lines below. Change-Id: I99c363b6f0ecfd07ad787b79b75e61771733c2b3 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-5/+81
| | | | | | | | | 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>
* Simplify the futex lock loop: no need for nested whileThiago Macieira2012-09-141-25/+23
| | | | | | | | | | | | | Once we enter the inner loop, we never exit it except to return from the lockInternal() function, so the rest is never executed again. As a consequence of this, we won't try to fastTryLock() twice per mutex. Therefore, for a non-recursive mutex, if lockInternal() is entered, we'll definitely need to use futexes. Change-Id: Ice617ed27449c1fbdc112a159a86cd0660125e13 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Make QBasicMutex be exclusively non-recursiveThiago Macieira2012-09-141-14/+6
| | | | | | | | | | | | | | | 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>
* Don't recheck about timeout == 0 during mutex lockingThiago Macieira2012-09-141-3/+4
| | | | | | | | | | | | | | If the timeout wasn't zero, it can only become zero if we return from futex() with a non-timeout reason but subsequently expires while we're recalculating something. A side effect is that we try-lock a non-recursive mutex exactly once. Before this change, we'd fastTryLock() twice even with timeout == 0. Change-Id: I0af09fc2a84669a683a843fcf1513203b075dfb7 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Hoist the recursive mutex check out of the inner loopThiago Macieira2012-09-141-24/+30
| | | | | | | | 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>
* Split the futexFlags() function in two: a hot and a cold pathThiago Macieira2012-08-251-18/+26
| | | | | | | | | | | | | | We could mark the cold path with __attribute__((cold)) (since GCC 4.3), but quick tests locally indicate that the compiler is smart enough to determine that by itself. It will inline the hot path in _q_futex, which in turn is inlined in the lockInternal and unlockInternal functions, whereas the cold path is kept outside. Change-Id: I8ae7d851d4f050498bfb491ba87d3e25453a14f8 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Mark mutex locking and unlocking functions with noexceptThiago Macieira2012-08-251-3/+3
| | | | | | | | | | | | | | | | | | | | | 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>
* Work around Android not having SYS_futex.Robin Burchell2012-05-021-2/+5
| | | | | | | | Even though we really shouldn't, we can get away with using __NR_futex instead. Done-with: Thiago Macieira <thiago.macieira@intel.com> Change-Id: I0ba449b740acf2c78825f8093d1515a74f0bc9cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix QMutex::tryLock timeout regression (integer overflow)Markus Rathgeb2012-04-241-1/+1
| | | | | | | | | | | | | | | | | The timeout given in milliseconds should be converted to a timespec struct. To separate the seconds and nanoseconds the milliseconds are first multiplied to represent the whole value in an int64 variable. The calculation is done on integers, so we get an overflow if the milliseconds are bigger then 2148. If we cast the given value to an int64 we can avoid this problem. Fix the used cast. Task-number: QTBUG-24795 Change-Id: I864ae227cf7dda16a6f30aa4db74acc49e20f6eb Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Use private futexes for QMutex on Linux if they're availableThiago Macieira2012-03-251-2/+35
| | | | | | | | | | | | Futexes on Linux can be used across processes, for inter-process synchronisation. The private flag tells the kernel that this futex is not used with other processes, so it does not need to check for waiters outside the current process. This feature had been proposed in Merge Request 25, but was lost. Change-Id: Ieafa8b8df0949bd9ae73709b3ec63f7709b0b2a6 Reviewed-by: João Abecasis <joao.abecasis@nokia.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>
* QRecursiveMutexPrivate should not inherit from QMutexPrivateOlivier Goffart2011-10-311-9/+4
| | | | | | | | 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-7/+7
| | | | | | | | | 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>
* Make all uses of QBasicAtomicInt and Pointer use load() and store()Thiago Macieira2011-10-031-6/+6
| | | | | | | | | | | | | | 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-0/+138
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>