summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
Commit message (Collapse)AuthorAgeFilesLines
...
* Do not define QT_BASIC_ATOMIC_HAS_CONSTRUCTORS for clang.Erik Verbruggen2012-11-071-1/+12
| | | | | | | | | | This triggers a bug in clang (before version 3.2). See also the bug report: http://llvm.org/bugs/show_bug.cgi?id=12670 . Change-Id: I9e0bc1cc39059ffa5e062652b932bc01e453ef98 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
* Review of documentation.Michele Caini2012-11-021-6/+25
| | | | | | | Documentation has been updated, changes apply to Qt5 as well as Qt4. Change-Id: I13241a3b4c16d2cb1b24f80fe26832467621923a Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Fix for leak in QFutureChristian Strømme2012-11-013-5/+46
| | | | | | | | | | | To avoid leaking when converting a QFuture<T> to a QFuture<void> we need to have a separate ref. counter for QFuture<T>. When the last QFuture<T> goes out of scope, we need to clean out the result data. Task-number: QTBUG-27224 Change-Id: I965a64a11fffbb191ab979cdd030a9aafd4436c2 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Remove stale QT_MODULE() usage casesKonstantin Ritt2012-10-251-2/+0
| | | | | | | As of Qt5, this macro is defined to be empty; simply get rid of these leftovers. Change-Id: I167ccb4c9e92ec9b5e4faeb02bf9c5ef5d982b50 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Trim trailing whitespace.Stephen Kelly2012-10-221-1/+1
| | | | | Change-Id: Iee6bb66831f53399e5937eab5704af835979f5c3 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Remove the QThread::terminated() signalSze Howe Koh2012-10-195-37/+9
| | | | | | | | | | | | | | | | | The signal is removed from the API; all references to it are removed from documentation; the unit test that checks for its emission is modified to listen for QThread::finished() instead. The QThreadPrivate::terminated flag is also removed, as it served no purpose other than to trigger the emission of QThread::terminated() As discussed at http://lists.qt-project.org/pipermail/development/2012-October/007216.html the signal is not guaranteed to be emitted after every termination, rendering it useless. Change-Id: I7b0c45d7889da0d33875545331606f2208ee56fc Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Fix for memory leak in ResultStoreChristian Strømme2012-10-181-1/+4
| | | | | | | | | | | In ResultStoreBase::addResults() it possible that the ResultItem we create is invalid (filter-mode enabled). Since an invalid ResultItem won't have any result data, we need to make sure that we don't allocate any data for it. Task-number: QTBUG-27224 Change-Id: Ic99b191db0e9dd4e29b64911f87d90a8148bb7a5 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
* QThread signals documentation improvementOlivier Goffart2012-10-151-2/+12
| | | | | | | | | Be more explicit on from which thread the signals are emitted, and mention that it is possible to connect finished with deleteLater Change-Id: Ib72be94a81be383774f08d71915fa609843030e0 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@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>
* Doc: Update QThread class ref to reflect changes since Qt 4.4Sze Howe Koh2012-10-081-55/+104
| | | | | | | | | | | | | | Remove advice to subclass QThread; promote thinking of QThread as a thread manager, not a thread; promote event-driven programming over time micromanagement; warn against common pitfalls. Result of collaboration in forum (https://qt-project.org/forums/viewthread/20691/) and mailing list (https://qt-project.org/pipermail/development/2012-September/006738.html) Task-number: QTBUG-16358 Change-Id: I57e3873976fad489176cbf9f7e680fd6992a8837 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
* qfuturesynchronizer.cpp: fix whitespace errorsMarc Mutz2012-09-281-14/+14
| | | | | Change-Id: I106ae536f1411939c3785f0a97c39752db59b19c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QException/QFuture*: add \inmodule QtCoreMarc Mutz2012-09-284-0/+5
| | | | | Change-Id: Iad787e3280889eae6b6aace9a85bda966b1a7094 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QFutureSynchronizer back to QtCoreMarc Mutz2012-09-283-0/+277
| | | | | | | This class, too, belongs with QFuture. Change-Id: I41a532ca66c156f1631e4b22ffc1a5879c854488 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QFutureWatcher back to QtCoreMarc Mutz2012-09-285-1/+912
| | | | | | | | This belongs with QFuture. Change-Id: I555cd01c1d3890fbbaca4fd8a9170292ea4eb0fb Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QFuture from QtConcurrent to QtCoreMarc Mutz2012-09-286-0/+2020
| | | | | | | | | This class belongs to QThreadPool/QRunnable more than to QtConcurrent, so move to QtCore, where QThreadPool awaits it. Change-Id: Ibf20288a986593bf779453427c2dae8db1e1423a Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QtConcurrent::ResultStore as QtPrivate::ResultStore to QtCoreMarc Mutz2012-09-283-0/+496
| | | | | | | | | | No compatibility header needed. While this wasn't marked as private API, it wasn't documented, either. This is a prerequisite for moving QFuture to QtCore. Change-Id: I8e986e6e2a22fbe5cf08d0600ec39ae9ae993e20 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QtConcurrent::Exception as QException back to QtCoreMarc Mutz2012-09-283-0/+331
| | | | | | | | | Leave the old name as a deprecated typedef; adapt users. This is a prerequisite for moving QFuture back to QtCore. Change-Id: I81dcee2c7e6eb234c16f3f42e2415ca0da3dc4f8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QPostEventList: change pointer comparison to integer comparisonMarc Mutz2012-09-271-1/+1
| | | | | | | | | | This is exactly the type of pointer arithmetics that GCC likes to miscompile. Just use offset >= size() (=subtract begin() from both sides). Change-Id: Ifb13652d7b96bf4c06727d9c965516e95d16ab5c Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Workaround MSVC2008 build failure after switching to std::upper_boundGiuseppe D'Angelo2012-09-271-7/+3
| | | | | | | | | | | | | | | | | QPostEventList is kept sorted by priority; std::upper_bound is used to insert a QPostEvent in the right place in the list. Turns out that MSVC2008 is a bit too picky and tries to see if the list is actually ordered. This causes a build failure as there is no operator< defined between two QPostEvents (in fact, an integer -- the priority -- is passed to std::upper_bound). Work around this issue by defining operator< between two QPostEvents. Change-Id: Ie3562dd0cc7253e25fc988b25d566d9d9e9fe62b Reviewed-by: Andreas Holzammer <andreas.holzammer@kdab.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix spelling mistakeThiago Macieira2012-09-271-1/+1
| | | | | | | Task-number: QTBUG-27355 Change-Id: I77ecc01e2a3ea1cac94e7c99c688cfd7cab5319b Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-2236-852/+852
| | | | | | | | 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-212-4/+54
| | | | | Change-Id: Ieb5632017e5e8e09a11dc6b929efa19b4f350086 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove qUpperBound usages from qtbaseGiuseppe D'Angelo2012-09-192-2/+6
| | | | | | | | | Replace them with std::upper_bound; this allows for deprecation of qUpperBound. Change-Id: Idef01d2228b9a70eee3d52931d7aedb5bb6ba902 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
* Move QRecursiveMutexPrivate to qmutex.cpp and mark inlineThiago Macieira2012-09-142-14/+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>
* Remove QBasicAtomic::tryLock with a timerThiago Macieira2012-09-141-2/+2
| | | | | | | | | | The non-futex implementation does not support timed locks in QBasicMutex. That is only supported in QMutex (due to the destructor). Change-Id: I46d33a66a36e05c8a4344823537178e80a6ddd76 Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@nokia.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>
* 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-143-6/+91
| | | | | | | | | 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-144-35/+52
| | | | | | | | | | | | | | | 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-142-27/+39
| | | | | | | | 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>
* Threads: Fix mingw-gcc warning about 'cast to pointer from integer of ↵Kai Koehne2012-09-131-4/+4
| | | | | | | | | | different size' Use reinterpret_cast to convert from DWORD to pointer. Change-Id: I17a12940850aeb0bc27080725a18eb93fee72ff7 Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
* Revert "Use true and false in preference to TRUE and FALSE"Sergio Ahumada2012-09-073-3/+3
| | | | | | | | | | | Even though I really think the change was the right thing to do, it seems like Windows people don't like this change because of some Windows Data Types specific rules. This reverts parts of the commit 56d5c909af6473be64a1ae487b45bd444a9a8553. Change-Id: I2c67d9b1bab36fc63937ef386aef56d2a4472a04 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
* Fix g++ compiler warnings.Friedemann Kleint2012-09-071-1/+1
| | | | | | | | Unused variables, unsigned comparison DWORD >= 0 is always true, format string. Change-Id: I9f0a20392e262b2542fb23ea4f513e4c4e354b68 Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
* Use true and false in preference to TRUE and FALSESergio Ahumada2012-09-053-3/+3
| | | | | | | | The TRUE and FALSE macros are obsolete and should be replaced with true and false (all lower case) respectively. Change-Id: Iee352e8173500683e6319be0abbf5bacf29016e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.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>
* 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-257-33/+37
| | | | | | | | | | | | | | | | | | | | | 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>
* Use nanosleep instead of pthread_cond_timedwait for thread sleepingThiago Macieira2012-08-251-40/+8
| | | | | | | | | | | | | | | There's a comment saying nanosleep's availability is questionable, but the information of what systems don't have that is now lost in time. It's quite likely that they were older, Unix systems we no longer support anyway. nanosleep comes from POSIX.1b-1993, which is merged into POSIX.1-2001, so chances are that it's supported almost everywhere where Qt runs (except for Windows anyway). Change-Id: I4fd18f8715c43a42429000f3b3d2c3b7343f94b4 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
* Doc: Add \inmodule QtCore to all QtCore class doc bodiesThiago Macieira2012-08-2310-0/+15
| | | | | Change-Id: I19100755c97cc155c76a859e19940e9f9222d34e Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
* QAtomic: make ctors constexpr, if possibleMarc Mutz2012-08-201-0/+12
| | | | | | | | | | | | This requires using the same chain of conditions that QBasicAtomic* uses in order to provide constructors, so we're using the newly-added macro QT_BASIC_ATOMIC_HAS_CONSTRUCTORS to check. Even though QAtomic<> is a template, we can't just use Q_DECL_CONSTEXPR since the body of the constructors needs to change, too. Change-Id: I462a80ed175040f7709c30d07d34036c6c5507d8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QBasicAtomic: add QT_BASIC_ATOMIC_HAS_CONSTRUCTORS macroMarc Mutz2012-08-201-2/+6
| | | | | | | | | | This macro is defined when the QBasicAtomic* types have constructors. It will be used to simplify maintenance of QBasicAtomic subclasses, as well as classes that aggregate Q(Basic)Atomics and wish to be literal types if possible. Change-Id: I7ab181c58a13ec2195449bbae5b3476b9017a8f2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add Q_DECL_CONSTEXPR to the isXXX functions in the new atomics.Thiago Macieira2012-08-183-36/+36
| | | | | | | | | This allows one to write code that depends on these values at compile-time. Change-Id: I7d78524ed9c70d4141360496d1d764dcbfa92e62 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark simple static methods in QThread as Q_DECL_NOTHROWThiago Macieira2012-08-183-6/+6
| | | | | | | | | | These methods aren't often used, but currentThreadId() gets used in the recursive mutex code to store the identity of the thread with multiple locks. Change-Id: I031cf3893aa6e7fd7a53733fc1088d295bdb9079 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QThreadPool: fix race on 'queue' in stealRunnable()Marc Mutz2012-08-171-1/+1
| | | | | | | | The code under mutex protection already implicitly handles the case where queue.empty(), so just removing the pre-lock check suffices. Change-Id: I01467aff62e61bb4efd16359dd64546ff51c6bad Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* QThreadPool: use swap() when making a copy of allThreadsMarc Mutz2012-08-171-3/+3
| | | | | | | This is the C++98 version of std::move(). Change-Id: Icb73da16bb05bf07114a38e4fd48732b612e2d51 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* QThreadPool: don't loop unless neededMarc Mutz2012-08-171-2/+2
| | | | | | | The resulting code is easier to understand, too. Change-Id: I3cd84d85b3186860dd3ccd67c3771b82695e7f83 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Fix compilation of QThread on QNXSean Harmer2012-08-171-4/+6
| | | | | | | | | | Commit 3ef51efbe75bfb9f1dfbe7df073e9eb745a72ad8 broke compilation of qthread_unix.cpp on QNX. This fixes it by passing in the threadId to setCurrentThreadName(). Change-Id: I24f32d8054baedbd9a65b6a80fb1f6f37e07092d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>