summaryrefslogtreecommitdiff
path: root/src/corelib/thread
Commit message (Collapse)AuthorAgeFilesLines
* QSemaphore: add QDeadlineTimer APIThiago Macieira2023-05-163-48/+57
| | | | | | | | This removes the last use of QtPrivate::convertToMilliseconds(). Change-Id: I6f518d59e63249ddbf43fffd1759fee2e00d36f4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Make QGenericRunnable a private nested class of QRunnableMarc Mutz2023-05-161-1/+2
| | | | | | | | | We don't intend to make QGenericRunnable public API, so prevent people from using it outside QRunnable::create(). Change-Id: I49f182463ca307aaf6370adfa43bae14b4ce0df8 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QReadWriteLock: inline the constructor and destructorThiago Macieira2023-05-112-5/+22
| | | | | Change-Id: Ieab617d69f3b4b54ab30fffd175b2500dd860431 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMutex: add QDeadlineTimer-based tryLocksThiago Macieira2023-05-115-33/+105
| | | | | | | | | | | | | | This simplifies the code greatly, because we don't need to use QtPrivate::convertToMilliseconds any more, as QDeadlineTimer has nanosecond precision. Internally it becomes simpler too because lockInternal was already using QDeadlineTimer. I just had to use the parameter instead and update the two non-futex implementations to take it again. This may even be fixing a mistake in case sem_timedwait(2) got interrupted. Change-Id: I6f518d59e63249ddbf43fffd1759fed9f50b3606 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QReadWriteLock: add tryLockForXxx overloads taking QDeadlineTimerThiago Macieira2023-05-113-48/+98
| | | | | | | | | | | | | | This propagates inside the internals, ending up in wait_until calls in the internal std::condition_variable. For systems with proper support for monotonic waiting (Linux, FreeBSD), this should improve performance. We could even remove the hasExpired() check and pass a time point in the past too. Right now, there's a minor performance drawback for tryLockForXxxx(), because we will make at least two system calls to get the time. Change-Id: I6f518d59e63249ddbf43fffd1759fc5b2e40256a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QReadWriteLock: inline the lockForXxx functionsThiago Macieira2023-05-112-8/+16
| | | | | | | | We can now do that because tryLockForXxxx(-1) is fast for the uncontended case too. Change-Id: I3d728c4197df49169066fffd1756ddd06caf7b52 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QReadWriteLock: remove the untimed tryLockForXxxx functionsThiago Macieira2023-05-112-44/+6
| | | | | | | | | | They're unnecessary now because the timed function is fast enough. Note: the default argument will move to the QDeadlineTimer functions before the Qt 6.6 release. Change-Id: I3d728c4197df49169066fffd1756ddc0e4f796d3 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QReadWriteLock: force the loop to exist in a separate functionThiago Macieira2023-05-111-2/+15
| | | | | | | | | | | This allows the fast, uncontended case to exist in a function that does much less work and therefore needs to save less state in its prologue. This is interesting too for LTO because the compiler can then inline the fast, uncontended path where the locks were used. Pick-to: 6.5 Change-Id: I3d728c4197df49169066fffd1756dc04d8a5f04a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QReadWriteLock: remove the private function from the symbol tableThiago Macieira2023-05-115-42/+57
| | | | | | | | | | Just move it to the private class. This also allows this function to get inlined in QWaitCondition::wait(). Pick-to: 6.5 Change-Id: I6f518d59e63249ddbf43fffd1759fc99c28c7ca8 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QRunnable: fix Coverity dead-code warnings in create()Marc Mutz2023-05-111-12/+20
| | | | | | | | | | | | | | | | | | | | | | | | Coverity complained about the call to warnNullCallable() being dead code for most instantiations of the create() function template. It's right, of course, even though warning in a template that clearly has instantations where it's not dead code isn't exactly helpful. Nonetheless, take the opportinity to avoid the dead code warning at the expense of a bit or un-DRY-ing: - because we now use them more than once, cache the result of is_*function_* predicates in constexpr variables - then scope the is_null variable such that its use is not subject to dead-code removal anymore (at instantiation time; it may still be removed by the optimizer) As drive-bys, add a comment about the reinterpret_cast, and make the custom template predicates variable- instead of class templates. Coverity-Id: 407640 Change-Id: I272223042c2aae9d814e82c466e1d29e1c42bfa1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* QGenericRunnable: remove common prefix from nested classesMarc Mutz2023-05-111-12/+11
| | | | | | | | Helps keep the code fit into line length limitations. Change-Id: I2e861c6f0a991cc36991572c4386040b8e11ca40 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QGenericRunnableHelper info QGenericRunnableMarc Mutz2023-05-111-7/+6
| | | | | | | | | Because we can, and it prevents all the machinery from being exported by the Q_CORE_EXPORT on QRunnable. Change-Id: I80e0690956bff612f2048eefb2b64bc198835f1f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Move handling of helper from create() to QGenericRunnableMarc Mutz2023-05-111-4/+4
| | | | | | | | Keeps the helper contained in QGenericRunnable. Change-Id: I52d075efc55c5eb78fe97ade261b58fc75e2a6c1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QGenericRunnable: use CompactStorageMarc Mutz2023-05-091-4/+6
| | | | | | | | ...optimizing the storage of empty function objects. Change-Id: I6db7384e1ebb87249d5b93922a6c92f0767cc401 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Future-proof QGenericRunnableHelperMarc Mutz2023-05-051-10/+21
| | | | | | | | | | | | Collapse the two function pointers into a single one, taking an Op enum. Add a possible return value (void*) and extra argument (also void*). The intent is to allow extensions in a BC way, e.g. cloning. We can't add new function pointers (sizeof changes), so we need to fold everything into a single function. Change-Id: Id0f3f74149c61e4e65622aeabfd2fcea3c6d7fb3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QMutex: remove unused tst_QMutex forward declarationThiago Macieira2023-05-041-3/+0
| | | | | | | | | | Commit d4b206b246caf9b49110526585693ab629609d99, which split QRecursiveMutex from QMutex and thus rewrote a lot of the tests, removed the friendship, but not the forward-declaration. Pick-to: 6.5 6.2 Change-Id: I6f518d59e63249ddbf43fffd1759d28f1547ec9f Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QRunnable: Extract Method warnNullCallable()Marc Mutz2023-05-042-5/+15
| | | | | | | | | | | | The warning doesn't depend on the template argument, so factor it into an out-of-line Q_DECL_COLD_FUNCTION. This will automatically mark the is_null check as [[unlikely]], too. As a drive-by, use printf-style qWarning() (expands to less code and doesn't require #include <qdebug.h>). Change-Id: I9ac2d912eb1d4f3d1d9b41d77700bed6d6850b0a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Take move-only functions for the threadpoolAllan Sandfeld Jensen2023-05-043-32/+85
| | | | | | | | | | | | We never copy the function so only need it to movable. Moves the functions to templates using the new QRunnable create version. [ChangeLog][QtCore][QThreadPool] Methods taking callable functions, can now take move-only lambdas. Fixes: QTBUG-112302 Change-Id: I2cb200f0abcf7e0fdbef0457fe2a6176764ad93d Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QMutex & QReadWriteLock: do a memory read before CASThiago Macieira2023-05-012-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The testAndSet operation is expensive if the lock is contended: attempting to CAS that lock will cause the cacheline containing the lock to be brought to the current CPU's most local cache in exclusive mode, which in turn causes the CPU that has the lock to stall when it attempts to release it. That's not desirable if we were just trying an untimed tryLock*. In the case of timed, contended tryLocks or unconditional locks, we still need to perform an atomic operation to indicate we're about to wait. For that case, this patch reduces the minimum number of atomic operations from 2 to 1, which is a gain even in the case where no other thread has changed the lock status at all. In case they have, either by more threads attempting to lock or by the one that has the lock unlocking it, this avoids the cacheline bouncing around between the multiple CPUs between those two atomic operations. For QMutex, that second atomic is a fetchAndStore, not testAndSet. The above explanation is valid for architectures with Compare-And-Swap instructions, such as x86 and ARMv8.1. For architectures using Load Linked/Store Conditional instructions, the explanation doesn't apply but the benefits still should because we avoid the expense of the LL. See similar change to pthread_mutex_lock in https://sourceware.org/git/?p=glibc.git;a=commit;h=d672a98a1af106bd68deb15576710cd61363f7a6 Change-Id: I3d728c4197df49169066fffd1756dcc26b2cf5f3 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Short live Q_NODISCARD_CTORIvan Solovev2023-04-301-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [ChangeLog][QtCore] Introduced Q_NODISCARD_CTOR which resolves to [[nodiscard]] attribute for constructors on compilers that support it, and does nothing on other compilers. Using [[nodiscard]] attribute on a constructor is a C++20 feature, however in practice it is supported on most of the compilers that we use in Qt 6. Clang generates a [-Wunused-value] warning, GCC and MinGW generate a [-Wunused-result] warnings, and MSVC generates a C4834 warning. However, there are some exceptions. The Integrity compiler provides the following warning: "tst_qglobal.cpp", line 699: warning #3435-D: the "nodiscard" attribute doesn't apply to constructors, destructors, or routines with void return type [[nodiscard]] explicit Test(int val) : m_val(val) {} The QNX compiler (QCC 8.3.0) and GCC 9.3.1 on OpenSUSE generate the [-Wattributes] warning: tst_qglobal.cpp: In member function 'void tst_QGlobal::nodiscardConstructor()': tst_qglobal.cpp:699:44: warning: 'nodiscard' attribute applied to 'tst_QGlobal::nodiscardConstructor()::Test::Test(int)' with void return type [-Wattributes] [[nodiscard]] explicit Test(int val) : m_val(val) {} These warnings will lead to build failures when compiled with -warnings-are-errors flag, so for these compilers the macro does not do anything. An attempt to use __attribute__((__warn_unused_result__)) was also unsuccessful on these compilers, so this patch goes for an easy solution, and simply checks __has_cpp_attribute(nodiscard) >= 201907L to decide if the attribute is supported or not. This commit also introduces a syntax-only test, and also applies the new macro to QMutexLocker, because not all platforms in the CI build and run unit tests. Fixes: QTBUG-104161 Change-Id: Ib4230661a5ad5e8af0d67b21b034486ebcd67562 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QReadWriteLock: don't mark fully-inline classes as exportedThiago Macieira2023-04-271-5/+5
| | | | | | | | | We can't remove the export in Qt 6 because of how MSVC ABI works. In all other compilers, this change is a no-op anyway (inline functions have hidden visibility). Change-Id: I3d728c4197df49169066fffd1756dc377b30c504 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Tighten template on new QRunnable create methodAllan Sandfeld Jensen2023-04-272-2/+8
| | | | | | | | Only instantiate with object/methods that are invokable with void and returns void. Change-Id: Iab2e43bb8e061e3875a6cca8e06ebbfbfa9e6fe8 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QMutex/Unix: remove the pthread_mutex_t-based contentThiago Macieira2023-04-253-72/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | For our purposes, the sem_t code is better, so we've preferred it since commit c7ab816af110ea08809e1aabd8bf1e08967c6d53 (5.7). Olivier wrote in that commit's message, "It makes tst_QMutex::contendedQMutex with no msleep 8 times faster". That's true because QMutex didn't lock the underlying pthread_mutex_t in QMutex::lock(), as we used the inlined atomic code for the uncontended case. It is probably possible to merge the qmutex_mac.cpp and qmutex_unix.cpp code now (both are based on semaphores), but I won't do that for two reasons: 1) At best, the PThread functions are going to be thin-wrappers around the code we already have, like FreeBSD's are around usem (see [1]) 2) Darwin has a private API that resembles futexes so we may want to go that way eventually (see [2]) [1] https://github.com/freebsd/freebsd-src/blob/main/lib/libc/gen/sem_new.c [2] https://codereview.qt-project.org/335849 Change-Id: Idd5e1bb52be047d7b4fffffd175369b13ba47bed Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Misc.: Fix some narrowing integral conversion warningsAhmad Samir2023-04-251-1/+1
| | | | | | | Drive-by change: use QByteArrayView instead of allocating a QByteArray. Change-Id: Iaf7acbbdb4efbb101b73b30061ce38dd1fa99ca3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QWaitCondition/Unix: sort and organize includesThiago Macieira2023-04-181-7/+6
| | | | | | Change-Id: Idd5e1bb52be047d7b4fffffd174ea54b8e954387 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QWaitCondition/Unix: use QDeadlineTimer's <chrono> supportThiago Macieira2023-04-181-17/+32
| | | | | | | | | | | We don't need to hand-roll our own conversions when QDeadlineTimer can convert to the time points of any std::chrono clock. In particular, if the clock we ask for is the clock its internal representation is already storing, then it's more efficient too. Change-Id: Ieec322d73c1e40ad95c8fffd174689a171cb6f18 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QWaitCondition/Android: remove support for relative time waitsThiago Macieira2023-04-181-24/+0
| | | | | | | | | | | | | | | | | This actually saves two clock_gettime(CLOCK_MONOTONIC) system calls (albeit to the vDSO): one inside QDeadlineTimer::remainingTimeNSecs() to calculate the remaining time from the deadline, then one other inside pthread_cond_timedwait_relative_np() to calculate the deadline from the timeout, so it can place the FUTEX_WAIT_BITSET system call. In fact, I can't find __pthread_cond_timedwait_relative() in the Bionic source any more. The last reference was removed in 2015, when Bionic started using FUTEX_WAIT_BITSET. So this commit is just removing dead code in current Android. Pick-to: 6.5 Change-Id: Ieec322d73c1e40ad95c8fffd174689c4fcff40ae Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QWaitCondition/Unix: Modernize the call to pthread_condattr_setclockThiago Macieira2023-04-181-5/+8
| | | | | | | | | | | | This avoids creating and destroying the pthread_condattr_t on systems without a monotonic clock (INTEGRITY) or for which we can't ask that pthread_cond_t use it (Darwin). Change-Id: Ieec322d73c1e40ad95c8fffd1746878316ab8708 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QElapsedTimer/Darwin: merge with the Unix implementationThiago Macieira2023-04-181-3/+2
| | | | | | | | | | | | | | | | | | | | | Old versions of the Apple operating systems did not implement the POSIX realtime monotonic clock, so we used the Mach absolute timer. The LLVM libc++ implementation[1] unconditionally uses CLOCK_MONOTONIC_RAW on these OSes: * macOS >= 10.12 * iPhoneOS >= 10.0 * tvOS >= 10.0 * watchOS >= 3.0 Qt 6 doesn't support the latter two and the former two are much older than what we require, so we can use this functionality too. [1] https://github.com/llvm/llvm-project/blob/main/libcxx/src/chrono.cpp Change-Id: Ieec322d73c1e40ad95c8fffd174641c723b81be2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Long live QPromise::emplaceResult/At()!Marc Mutz2023-04-122-6/+39
| | | | | | | | | | | | And implement the rvalue overload of addResult() using it. [ChangeLog][QtCore][QPromise] Added emplaceResult() and emplaceResultAt() member functions. Fixes: QTBUG-112270 Change-Id: Id369542215a60c0818f1afa8d564498be84732e8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Deprecate QtFuture::makeReadyFuture()Ivan Solovev2023-04-053-0/+25
| | | | | | | | | | | | | | | | | | | [ChangeLog][Deprecation Notice][QtCore] The QtFuture::makeReadyFuture() method and all its specializations are deprecated since Qt 6.10. The reason for the deprecation is that the method has a makeReadyFuture(const QList<T> &) overload, which behaves differently from all other overloads (including other non-const ref QList overloads). Use QtFuture::makeReadyVoidFuture() when you need a ready void QFuture, or QtFuture::makeReadyValueFuture() when you need to propagate the input type to the returned QFuture, or QtFuture::makeReadyRangeFuture() when you need to create a multi-value future based on an input container. Fixes: QTBUG-109677 Change-Id: I55125269989df0a02840d5ddd5763ef5f1070df5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Long live QtFuture::makeReadyVoidFuture() and QtFuture::makeReadyValueFuture()Ivan Solovev2023-04-054-27/+87
| | | | | | | | | | | | | | | | [ChangeLog][QtCore][QFuture] Added QtFuture::makeReadyVoidFuture() and QtFuture::makeReadyValueFuture(). Basically, these methods behave like QtFuture::makeReadyFuture(), but QtFuture::makeReadyValueFuture() does not have a "const QList<T> &" specialization returning QFuture<T> instead of QFuture<QList<T>>, which allows it to always behave consistently. This patch also introduces usage of the new methods around qtbase. Task-number: QTBUG-109677 Change-Id: I89df8b26d82c192baad69efb5df517a8b182995f Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Long live QtFuture::makeReadyRangeFuture()Ivan Solovev2023-04-052-9/+84
| | | | | | | | | | | | | | | | [ChangeLog][QtCore][QFuture] Introduce QtFuture::makeReadyRangeFuture(). This method takes a container which has input iterators and returns a multi-value QFuture<ValueType>, where ValueType is the underlying type of the input container. This commit also replaces the usage of buggy QtFuture::makeReadyFuture(const QList<T> &) overload with the new method. Task-number: QTBUG-109677 Change-Id: I019e62eac74c643d88a65b3cc0085bc7c33bc712 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Create any callable using QRunnable::createAllan Sandfeld Jensen2023-04-042-20/+65
| | | | | | | | | | | | The overhead of making new custom classes appears to be less than constructing a generic std::function. [ChangeLog][QtCore][QRunnable] QRunnable::create can now take non-copyable functions as argument. Task-number: QTBUG-112302 Change-Id: Ied870f13ca6c7eaa14ed6eff9c4e676c7b73881c Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QElapsedTimer: remove the runtime check for the monotonic clockThiago Macieira2023-04-011-4/+4
| | | | | | | | | | | | There is no supported OS with a "maybe" monotonic clock. All of the OSes we currently support either always have a monotonic clock in the first place or never have one. There's only one OS in the latter category and that's INTEGRITY, lacking even the CLOCK_MONOTONIC constant. Change-Id: Ieec322d73c1e40ad95c8fffd17463531dae2c5bc Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QFutureInterface: Extract Method reportAndEmplaceResult() from ↵Marc Mutz2023-03-311-2/+11
| | | | | | | | | | reportAndMoveResult() This will be the building block for emplacement support in QPromise. Task-number: QTBUG-112270 Change-Id: Ie267e76fe078a8f7b3ef8c7e0d2abfcd22062ff2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QResultStore: add emplaceResult<T>()Marc Mutz2023-03-311-4/+9
| | | | | | | | | ... use it in moveResult(). Task-number: QTBUG-112270 Change-Id: I1233a710801d73c9153439b74a7a3900d2d9e39d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFutureInterface::reportAndMoveResult(): don't spell a move as forward<T>()Marc Mutz2023-03-311-1/+1
| | | | | | | | | | | | | | | The T&& result argument is not deduced (T is the template class' template argument, so it's an rvalue reference, not a Universal Reference, assuming that we don't support QFutureInterface<U> where U is a reference type). So std::forward<T> will always be a std::move(), so use that directly instead of raising eyebrows in the reader of the code by using forward<> to feed a function called _move_Result(). Pick-to: 6.5 Change-Id: I805df4686b5b74da57f8212b052b4056943a15fa Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QResultStore::moveResult(): refuse to move from lvaluesMarc Mutz2023-03-311-0/+2
| | | | | | | | | | | | | The T&& result argument is deduced, therefore result is a Universal Reference and as such can bind to lvalues, not just rvalues. If passed an lvalue, the function would happily move away from it, which is not what the doctor prescribed. Catch the attempt with a static assertion. Pick-to: 6.5 Change-Id: Iff8c1abd5dcb1043ed94ba76570be5ba3d6f92da Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QResultStore: use unconditional move() in moveResult()Marc Mutz2023-03-311-1/+1
| | | | | | | | | | | | | | | | | | | If the move can fail, so can most likely the copy. Use of move_if_noexcept() therefore trades a faster potentially-throwing operation for a slower potentially-throwing operation. It is true that a throwing move ctor may leave the source object in a partially-formed state while the copy ctor may not (exceptions prove the rule, hello auto_ptr), but we shouldn't pessimize lazy coders (missing noexcept) to cater for borderline-buggy code (throwing move ctor that doesn't provide the strong exception guarantee). Yes, you can construct such situations (and something as simple as std::array<std::pmr::string, 10> is already affected), but we don't cater for these anywhere else in Qt, so why do it here? Change-Id: I728af8e87ed86f24326530f704a48df1f728ac98 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QPromise: add support for addResult(braced-initializer)Marc Mutz2023-03-281-1/+1
| | | | | | | | | | | | | The usual problem, the usual fix: default the addResult() template argument to the class template argument, cf. e.g. wg21.link/p2218. [ChangeLog][QtCore][QPromise] Added support for calls to addResult() with braced initializers. Fixes: QTBUG-111826 Change-Id: I9ad7294dbcefbc5d2609ca3d9e7304dbeb8b3f41 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFutureInterface: add a warning when an existing continuation is overwrittenIvan Solovev2023-03-282-0/+13
| | | | | | | | | ... and also extend the documentation to explain this case explicitly. Fixes: QTBUG-107545 Pick-to: 6.5 6.2 Change-Id: I9414cc677b037989de60e97871485018e5c8a569 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definitionEdward Welbourne2023-03-204-8/+8
| | | | | | | | | | I got tired of being told off by the inanity 'bot for faithfully reflecting existing #if-ery in new #if-ery. Retain only the documentation and definition of the deprecated define. Change-Id: I47f47b76bd239a360f27ae5afe593dfad8746538 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QThread: add sleep(std::chrono::nanoseconds) overloadAhmad Samir2023-03-134-16/+38
| | | | | | | | | | | | | | All the other overloads are implemented using the new one. Windows change relies on the pre-check in the code review making sure it compiles. [ChangeLog][QtCore][QThread] Added sleep(std::chrono::nanoseconds) overload. Task-number: QTBUG-110059 Change-Id: I9a4f4bf09041788ec9275093b6b8d0386521e286 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMutex: add missing includeAhmad Samir2023-03-051-0/+2
| | | | | Change-Id: I43dba6811e7a31990e767d7ca13fdd518109217e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QThread/Unix: move qt_nanosleep to qthread_unix.cppThiago Macieira2023-02-251-0/+14
| | | | | | | | | It's the only place that uses it. Pick-to: 6.5 Change-Id: Ieec322d73c1e40ad95c8fffd17465370ac209c2f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Add special thread pool for Qt GuiAllan Sandfeld Jensen2023-02-252-0/+17
| | | | | | | | | To avoid gui slowdowns due to global pool being blocked. Fixes: QTBUG-109511 Pick-to: 6.5 6.4 6.2 Change-Id: I4e8d91e8fb0bd2e395072a082e992a3c5d3464ad Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QThreadPool: Protect the access to internal data with mutexJarek Kobus2023-02-221-0/+7
| | | | | | | | | | | | The class claims to be thread safe, however, when e.g. one thread is calling setMaxThreadCount() and the second is calling maxThreadCount() at the same time for the same thread pool instance, the latter may receive rubbish data. Protect all public setters/getters with a mutex. Pick-to: 6.5 6.4 Change-Id: Ief29d017d4f80443fa1ae06f6b20872f07588768 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QReadWriteLock: Resolve a redefinition issueAmir Masoud Abdol2023-02-201-12/+11
| | | | | | | | | This collides with a similarly name struct/object in qmutex.cpp. Pick-to: 6.5 Task-number: QTBUG-109394 Change-Id: I29404f092db523e21f310b4e5b3cd8cc35170e4a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtMiscUtils: add std::chrono::duration <-> timespec helpersAhmad Samir2023-02-201-15/+6
| | | | | | Change-Id: I91f36a3d651fd57443072fde4c3e8f811682328e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>