summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
Commit message (Collapse)AuthorAgeFilesLines
* Forbid implicit conversions between QFuture and other typesSona Kurazyan2020-10-302-21/+1
| | | | | | | | | | | | | | | | | | | | | - Remove the casting operator of QFuture<T> to T. It calls QFuture::result(), which may lead to undefined behavior if the user has moved the results from QFuture via QFuture::takeResult() before trying to do the conversion. - Disable implicit conversion of QFuture<T> to QFuture<void>, by making the constructor explicit. If the users really intend to do the conversion, they should do it explicitly. [ChangeLog][Source-Incompatible Changes][QFuture] Implicit conversions of QFuture<T> to T and to QFuture<void> have been disabled. Use QFuture::result() or QFuture::takeResult() where you need to convert QFuture<T> to T. Use the explicit QFuture<void>(const QFuture<T> &) constructor to convert QFuture<T> to QFuture<void>. Change-Id: I153d4137d36365b1611ac934fb3ac2eb667fdd6c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
* Remove the comparison operators of QFutureSona Kurazyan2020-10-293-15/+1
| | | | | | | | | | | | | | These operators don't do what the user might expect and may lead to confusing results. [ChangeLog][Source-Incompatible Changes][QFuture] The comparison operators of QFuture have been removed. They were comparing the underlying d-ptrs instead of comparing the results (as the users might expect), which is not very helpful for the users point of view. Change-Id: I80a887610eac38b60329128cca52cdb5fb515207 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* QtConcurrent: Integrate runWithPromise into runJarek Kobus2020-10-281-3/+3
| | | | | | Change-Id: I6eb95aa66ff847e8bb9aac348fded3a5d55015b6 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Store std::exception_ptr in QUnhandledExceptionSona Kurazyan2020-10-262-6/+96
| | | | | | | | | | | | | | | | For historical reasons Qt Concurrent reports QUnhandledException in case if an exception that is not derived from QException is thrown from a worker thread. Changing this behavior may not be a good idea, since the existing user code may rely on it. Changed QUnhandledException to wrap the std::exception_ptr to the actual exception, so that the users can obtain the information about the thrown exception if needed. [ChangeLog][QtCore][QUnhandledException] Improved QUnhandledException to store the std::exception_ptr to the actual exception thrown from a QtCocnurrent worker thread. Change-Id: I30e7c1d3e01aff6e1ed9938c421da0a888f12066 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtConcurrent: Reuse ArgResolver from qfuture_impl.hJarek Kobus2020-10-261-0/+46
| | | | | | Task-number: QTBUG-83331 Change-Id: I572f68f6d3be4a50970d8d77d070f175be3ec785 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Use American "canceled" in QPromise docsAndrei Golubev2020-10-221-5/+5
| | | | | Change-Id: I4c416f52c7102750a77c3f91274dd0a235569d6e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Whitespace cleanup in corelib/ mimetypes, plugin and threadAllan Sandfeld Jensen2020-10-2113-43/+42
| | | | | | | Done with selective application of clang-format Change-Id: Iee6bf2426de81356b6d480629ba972f980b6d93d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix qdoc warnings from QMutex and QMutexLockerVolker Hilsheimer2020-10-211-20/+7
| | | | | Change-Id: I25faab16ad2df3682e6c6b55d4aaff1c20402995 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Drop constexpr from QAtomicTraits::isLockFree()Edward Welbourne2020-10-201-19/+17
| | | | | | | | | As requested by a ### Qt 6 comment. This then implied a few other functions weren't constexpr, which broke some tests. Task-number: QTBUG-85700 Change-Id: I6522a9b2d7a74e117442121400a1d7198d323967 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QThread::create: mark as [[nodiscard]]Giuseppe D'Angelo2020-10-201-2/+2
| | | | | | | Also mark the helper function. Change-Id: I1469abf22cd132dbb1afe680121b6c928ffbe41e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Inline the members for QRecursiveMutexLars Knoll2020-10-172-72/+36
| | | | | | | Avoid creating a a d pointer for recursive mutexes. Change-Id: I28af15a416ee17de346e2ea5b1442279d9d3e159 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* <chrono> should always be available with C++17Lars Knoll2020-10-171-6/+0
| | | | | Change-Id: Ia4868259bfa25e4b929a51de6de580df7277c282 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Split QMutex and QRecursiveMutexLars Knoll2020-10-176-243/+238
| | | | | | | | | | | | | | | | | | | | | | | These classes should not inherit from each other anymore in Qt 6. The reason is that this makes the 95% case of using a non-recursive mutex much slower than it has to be. This way, QMutex can now inline the fast path and be pretty much as fast as QBasicMutex is in Qt 5. They actually use the same code paths now. The main difference is that QMutex allows calling tryLock() with a timeout, which that is not allowed for QBasicMutex. [ChangeLog][QtCore][QMutex] QMutex does not support recursive locking anymore. Use QRecursiveMutex for that purpose. QRecursiveMutex does not inherit QMutex anymore in Qt 6. Change-Id: I10f9bab6269a9181a2e9f534fb72ce65bc76d989 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Refactor QMutexLocker to be able to handle recursive mutexesLars Knoll2020-10-173-44/+31
| | | | | | | | Since we're going to split QMutex and QRecursiveMutex into separate classes, make sure QMutexLocker is prepared for that. Change-Id: Id5e9a955d1db7c8ee663dd3811ad6448dad0aeae Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove redundant duplicate of EnableForNonVoid in QFutureWatcherAndrei Golubev2020-10-161-7/+1
| | | | | | | | | qfuturewatcher.h includes qfuture.h, which includes EnableForNonVoid through qfuture_impl.h header. Thus, there is never a need to keep the same alias in QFutureWatcher as it always can use one from QFuture Change-Id: I293fd087aea1a21ef5bcfdf50cdefc176a9703d0 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Fix subtle SFINAE problem in QPromise::addResultAndrei Golubev2020-10-161-3/+1
| | | | | | | | | | | | | | Accidentally found out that we enable/disable QPromise::addResult based on type deduced from input argument, instead of using "value_type" of QPromise itself, which is wrong Simplified the checks to a single one - EnableIfSameOrConvertible<InputType, StoredType> as this is sufficient to account for both cases: QPromise<void> and QPromise<T> with input, convertible to T Change-Id: I657998c0e26241b0fc5e70988622984ece8871df Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Rename QPromise starting and finishing methods to start and finishAndrei Golubev2020-10-162-13/+13
| | | | | | | | | Proposed during API review Change-Id: I9c43e1915c50803ab69bfe07a91c05d2224b86c4 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Make QPromise::addResult() return boolean status of operationAndrei Golubev2020-10-163-49/+56
| | | | | | | | | | | | | | | Changed QPromise::addResult() to return bool value. True is returned when result is added and false is returned when e.g. promise is in final state (canceled or finished) or when addResult() is called twice with the same index as argument (in which case new value is rejected) Updated QFutureInterface::reportFinished() that accepts optional result as argument to align with other result adding methods. This function is "internal" only (as of now), so no documentation update is needed Change-Id: I2d63069246e5e5c8cf04529c22bb296faaaae53d Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Reject overwrites by the same index in QPromise::addResult()Andrei Golubev2020-10-134-8/+49
| | | | | | | | | | | | One can call addResult(value, index) twice and consequently set the value twice by the same index. This seems rather strange and probably should not be allowed. This commit rejects setting results when there's already a valid result by that index. Consequently, this fixes memory leaks caused by N-times-called addResult(..., index) Fixes: QTBUG-86828 Change-Id: I77494f2cb73ce727ffad721cfcdcaa420899eb25 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Temporarily disable QFuture::takeResult() methodSona Kurazyan2020-10-123-25/+40
| | | | | | | | | | | | QFuture::takeResult() currently returns std::vector instead of QList, because QList does not support move-only types. Disable this method until QList is fixed to work with move-only types in Qt 6.1. Also did minor doc-fixes. Change-Id: I87feaf75d9433a3b540edd00039c3e21d6994985 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Fix build when configuring with -sanitize thread on gccMitch Curtis2020-10-121-1/+1
| | | | | | | | | There is no <sanitizer/tsan_interface.h> header when building with gcc, at least on Ubuntu 18.04.3. Fixes: QTBUG-87317 Change-Id: Ie933f6fa478f11b5062c665007e91be68e31ebe3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make result finding procedure in ResultStore a free-standing functionAndrei Golubev2020-10-091-28/+38
| | | | | | | | | | Moved the logic of finding a result in ResultStore to separate function and parameterized it with QMap<...>. This is a pre-step to make find procedure uniform regardless of the storage we are looking in (either visible or pending as of now) Change-Id: I41641d70751925f223e992f52fbc7814085c452d Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Clear pending results in ResultStoreAndrei Golubev2020-10-091-9/+18
| | | | | | | | Pending results were never cleared by result store. This led to memory leaks when the results never transitioned to "visible" results Change-Id: I674302eb51542ad5f4d918da68d616428c73ae9f Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Another round of replacing 0 with nullptrAllan Sandfeld Jensen2020-10-072-2/+2
| | | | | | | | | This time based on grepping to also include documentation, tests and examples previously missed by the automatic tool. Change-Id: Ied1703f4bcc470fbc275f759ed5b7c588a5c4e9f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Centralize the implementation of move assignment operatorsGiuseppe D'Angelo2020-10-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment we have two main strategies for dealing with move assignment in Qt: 1) move-and-swap, used by "containers" (in the broad sense): containers, but also smart pointers and similar classes that can hold user-defined types; 2) pure swap, used by containers that hold only memory (e.g. QString, QByteArray, ...) as well as most implicitly shared datatypes. Given the fact that a move assignment operator's code is just boilerplate (whether it's move-and-swap or pure swap), provide two _strictly internal_ macros to help write them, and apply the macros across corelib and gui, porting away from the hand-rolled implementations. The rule of thumb when porting to the new macros is: * Try to stick to the existing code behavior, unless broken * if changing, then follow this checklist: * if the class does not have a move constructor => pure swap (but consider ADDING a move constructor, if possible!) * if the class does have a move constructor, try to follow the criteria above, namely: * if the class holds only memory, pure swap; * if the class may hold anything else but memory (file handles, etc.), then move and swap. Noteworthy details: * some operators planned to be removed in Qt 6 were not ported; * as drive-by, some move constructors were simplified to be using qExchange(); others were outright broken and got fixed; * some contained some more interesting code and were not touched. Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Remove unnecessary ref-counting of QRunnableAllan Sandfeld Jensen2020-10-012-32/+7
| | | | | | | It could never be higher than 1 anyway. Change-Id: If33c7978a4397a08e9eb091926726725d8bd3ea6 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Fix race condition in QThreadPool::clearAllan Sandfeld Jensen2020-10-011-3/+3
| | | | | | | | | | | Since we drop the lock while deleting threads, we need to handle the queue possibly being accessed and changed by the pool threads while clear() is running. Pick-to: 5.15 Fixes: QTBUG-87092 Change-Id: I7611edab90520454278502a58621e299f9cd1f6e Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Get rid of some #ifdef qt6Allan Sandfeld Jensen2020-09-301-8/+0
| | | | | | | | | None of this code is even compiled in qt6. Change-Id: I5891cc9459320083ad3908fcbf646f3ba75b8a4d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Improve docs for QFuture::{result*, takeResult*}Sona Kurazyan2020-09-291-4/+10
| | | | | Change-Id: I559f2fd73a9aae3d126be18cb259f8a9abe0efaf Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Replace Q_REQUIRED_RESULT with [[nodiscard]]Allan Sandfeld Jensen2020-09-251-1/+1
| | | | | | | It was already used many places directly making the code inconsistent. Change-Id: I3b14bc6c333640fb3ba33c71eba97e78c973e44b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* qwaitcondition_win.cpp: Fix deprecation warning about QMutex::isRecursive()Friedemann Kleint2020-09-251-4/+0
| | | | | | | | | Remove the check since a QMutex can no longer be recursive, fixing: qwaitcondition_win.cpp:164:28: warning: 'bool QMutex::isRecursive() const' is deprecated: Use QRecursiveMutex instead of a recursive QMutex [-Wdeprecated-declarations] Task-number: QTBUG-85700 Change-Id: Ic1631c1e671cf3234b5823d6d20121d746304c8e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Deprecate QMutex in recursive modeLars Knoll2020-09-213-5/+12
| | | | | | | | | Use QRecursiveMutex instead. Pick-to: 5.15 Change-Id: I862fc2b3143deeb5c96dc8d445be5f9fa2535670 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Improve docs for QtFuture::Launch::Sync policySona Kurazyan2020-09-181-6/+13
| | | | | | | | Updated QFuture docs to be more precise about QtFuture::Launch::Sync policy. Change-Id: Ic267c71f858e04a47ea1fc0996ea342d5eae7744 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Remove an outdated compiler checkSona Kurazyan2020-09-181-2/+0
| | | | | Change-Id: I3af019b65835b2f82161d6f1c24feb0523a32c11 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Purge Q_{STDLIB,COMPILER}_UNICODE_STRINGSEdward Welbourne2020-09-141-4/+0
| | | | | | | | | These were now always defined, hence redundant. Leave the #define in place so that we can verify we actually do always define it, in a #else of an existing #if check on it. Change-Id: Iea4c3dbc8f9982268bcf81da5ef17fe2ebf5c462 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Inline one method as per ###Qt6Lars Knoll2020-09-122-8/+6
| | | | | | Change-Id: I4bf0ddf4ddf4044a60d881a57ef63b96d4bac262 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Remove redundant non-const QMutex::isRecursive()Edward Welbourne2020-09-102-15/+0
| | | | | | | | As directed by ### Qt 6 comment. Task-number: QTBUG-85700 Change-Id: Iae4179b017840efe4902de2b1529cf7ec0606865 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QSemaphore: Make 64-bit wideThiago Macieira2020-09-081-1/+3
| | | | | | | | | | | | | | | | | | | | | | | The implementation can be more efficient with two 32-bit fields instead of just one, but it depends on whether operations on 64-bit atomics are locked or not. Quick check for the following architectures does not reveal any problems, but someone needs to investigate more. Notably, GCC and Clang generate a call to libatomic's __atomic_load_n / __atomic_store_n / etc. 32-bit std::atomic<uint64_t> Arch ::is_always_lock_free .is_lock_free() ARMv7-A false true i386 false true MIPS false true PPC false true RISC-V false true SPARC false true Change-Id: Ia2273af1172d493092d6fffd163251a99064c51b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Revert "Cleanup QSemaphore and make it always 64bit large"Thiago Macieira2020-09-092-60/+104
| | | | | | | | | | | | This reverts commit ff69227a49119c00f703cf89c9d72db7eeeeaa66. Reason for revert: 64-bit atomics on 32-bit systems are often (but not always) worse than the 32-bit semaphore as it was implemented. Plus the High32 and Low32 functions are returning the same thing, forgetting the endianness check. Change-Id: I5d5ade6e9bc7086600ff2302546385151e32142b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Cleanup QSemaphore and make it always 64bit largeLars Knoll2020-09-052-104/+60
| | | | | | | | This simplifies the implementation so that we don't need separate code paths for 32 and 64 bit anymore. Change-Id: I823612865e7d648fb0bd1632385ce67b5a452b8a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove some comments that are no longer relevantEdward Welbourne2020-09-051-2/+0
| | | | | | | Task-number: QTBUG-85700 Change-Id: I5ce368e8edca2b9483a0f0ef34bc9eb6b4e44574 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix QFuture::waitForFinished to wait until QFuture is startedSona Kurazyan2020-08-263-4/+4
| | | | | | | | | | | | | | | | | Currently QFuture::waitForFinished() exits as soon as the future is not in the running state. If the user calls it before QPromise::reportStarted() is called, it will exit immediately, because nothing is running yet. Fix the behavior to wait for the finished state. [ChangeLog][Important Behavior Changes][QtCore] Fixed the behavior of QFuture::waitForFinished() to wait until the future is actually in the finished state, instead of exiting as soon as it is not in the running state. This prevents waitForFinished() from exiting immediately, if at the moment of calling it the future is not started yet. Task-number: QTBUG-84867 Change-Id: I12f5e95d8200cfffa5653b6aa566a625f8320ca8 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Android: Fix currentThreadId to work on Android emulatorAlexandru Croitor2020-08-261-2/+2
| | | | | | | | | | | | | | | | | | | Apparently the Linux asm assumptions are not correct for the x86 Android emulator and this caused Android apps not to work properly: signal connections being queued instead of being direct, crashes in QPropertyAnimation, etc. Using currentThreadIdImpl on the Android emulator works fine though. Optimizing the code for the Android emulator case can be done in another change. Amends 5e9b2ade678f37e43bfc2e3484f54cbbb5844d2e Fixes: QTBUG-85640 Change-Id: I3b3ba76ea143aed949a6e50678c850b6ba231476 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Doc: Improve thread safety docsPaul Wicking2020-08-201-1/+15
| | | | | | | | | | | | * Add missing \threadsafe command. * Add missing note for methods callable only from the started thread. * Expand note on excerting care when interacting with objects across threads in QThread's class overview documentation. Fixes: QTBUG-86112 Pick-to: 5.15 Change-Id: I8f181d92ad6196ff0c13f5a866a36793209a75ab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtConcurrent: Introduce runWithPromise()Jarek Kobus2020-08-192-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The differences to run() method: 1. The passed function should have additional argument QPromise<T> &, declared as a first argument. 2. The return value of the function must be void. Result reporting should be done through passed QPromise<T> &promise argument. 3. By default, runWithPromise() doesn't support functors with overloaded operator()(). In case of overloaded functors the user needs to explicitly specify the result type as a template parameter passed to runWithPromise, like: struct Functor { void operator()(QPromise<int> &) { } void operator()(QPromise<double> &) { } }; Functor f; runWithPromise<double>(f); // this will select the 2nd overload Task-number: QTBUG-84702 Change-Id: Ie40d466938d316fc46eb7690e6ae0ce1c6c6d649 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Replace Qt CONSTEXPR defines with constexprAllan Sandfeld Jensen2020-08-148-75/+75
| | | | | | | | Both normal and relaxed constexpr are required by our new minimum of C++17. Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QAtomic*: purge deprecated load() and save() methodsEdward Welbourne2020-08-143-66/+3
| | | | | | | | Deprecated in 5.14 in favor of loadRelaxed() and storeRelaxed(). Caught one surviving use of load() in the ios platform plugin. Change-Id: I9518064a948e5d26ccb956490cbb0561bed5d8b5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Another round of using noexcept instead of pre-C++11 definesAllan Sandfeld Jensen2020-08-132-26/+4
| | | | | | | A few new files were added with old-school defines. Change-Id: Ieb2c71e094e55102f3f39fb9551823f36863f5f4 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Introduce swap functions for QPromise/QFutureInterfaceAndrei Golubev2020-08-034-15/+35
| | | | | | | | | | Made QPromise::swap public, added free standing swap() for QFutureInterface and QPromise. Updated QPromise special member functions. Extended tests Task-number: QTBUG-84977 Change-Id: I5daf6876df306d082441dbcdf5ae4dee3bfc0ead Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Another round of 0->nullptr cleanupAllan Sandfeld Jensen2020-07-311-4/+4
| | | | | Change-Id: Ic8db7dc252f8fea46eb5a4f334726d6c7f4645a6 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>