summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthread.h
Commit message (Collapse)AuthorAgeFilesLines
* QThread: Introduce static isMainThread() helperJarek Kobus13 days1-0/+1
| | | | | | | | | | | | Useful for QtCreator, as a replacement for Utils::isMainThread() inside threadutils.h, may serve for other projects, too. Introduce static QCoreApplicationPrivate::theMainThreadId atomic helper field holding the id of the main thread. Change-Id: Iccc0302f423f47b5ecad86c4cd3de4d1ee36155f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QThread: Introduce isCurrentThreadFabian Kosmale13 days1-0/+2
| | | | | | | | | | This allows a more efficient way of checking whether a thread is the currently executing one (without using private API). Change-Id: I007edae6b258d7e42e901fa720d4f3cf9fe25a49 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* QThread::currentThreadId: fix build on x32 (ILP32) ABIThiago Macieira2024-02-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | On this ABI, pointers are 32-bit, so Qt::HANDLE (void *) is a 32-bit variable and the "movq" instruction is inappropriate. There's a GCC extended inline assembler modifier for the instruction size suffix (%z0) but Clang seems not to understand it. Instead, I just removed the suffix: we can do that because this is a memory load instruction, which implies the destination is a general purpose register (also required by the "=r" constraint) and therefore the assembler can determine the size of the memory load from the name of the selected register. Note: I did not verify this compiles on x32 at all, much less that it loads the right thing from memory. Fixes: QTBUG-122674 Pick-to: 6.5 6.6 6.7 Change-Id: I01ec3c774d9943adb903fffd17b6513d146e89ce Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* CMake: remove check for cxx11_futureThiago Macieira2023-08-021-10/+2
| | | | | | | | | | | Everyone must have this by now. This test was 1193 ms of CMake time. Since this was a PUBLIC feature, I've left it around with a constant condition. Change-Id: Ifbf974a4d10745b099b1fffd177754538bbff245 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QEventLoopLocker: rewrite to hold public classesMarc Mutz2023-07-091-0/+2
| | | | | | | | | | | | | | | | | | ... instead of Private ones, at the cost of having to befriend of all the lockable classes, because we need access to their d_func()'s. This simplifies the code, because we don't need the manual QClass to QClassPrivate mapping (o2p) anymore, we can just use d_func(). This also paves the way to make QEventLoopLocker almost completely inline and use a 3-pointer form of QBiPointer, once available, to hide the bit fiddling. We couldn't make such a change if the class continued to hold pointers to QClassPrivate's. Pick-to: 6.6 Task-number: QTBUG-114793 Change-Id: Id300e4d45d6cacabe090a46cd6433c5ead3c8b0c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Deprecate some older Apple platform definesTor Arne Vestbø2023-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | Clang's macro deprecation pragma was introduced in Clang 14, shipped with Xcode 14.0. We can't version check Q_CC_CLANG here, as qcompilerdetection.h hasn't been included at this point. Nor would it have helped much, as we would have had to do so for each individual define we wanted to deprecate, since mentioning an undefined define in the deprecation pragma is an error. And we can't wrap the pragma in another macro that conditionally expands to _Pragma either, as the input argument is a define that needs to be passed on as is, without expanding it. So the simplest way to support < Xcode 14 is just to silence the unknown pragma warning. Pick-to: 6.6 Change-Id: Icf95042e6186deb212cd1793eb12ba32206ce34b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QThread: add sleep(std::chrono::nanoseconds) overloadAhmad Samir2023-03-131-0/+1
| | | | | | | | | | | | | | 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>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | To allow the user to customize the C++ code that QDoc sees, so as to be able to work-around some limitations on QDoc itself, QDoc defines two symbols: Q_QDOC and Q_CLANG_QDOC, both of which are "true" during an entire execution of QDoc. At a certain point in time, QDoc allowed the user the choice between a custom C++ parser and a Clang based one. The Q_QDOC symbol would always be defined while the Q_CLANG_QDOC symbol would be defined only when the Clang based parser was chosen. In more recent times, QDoc always uses a Clang based parser, such that both Q_CLANG_QDOC and Q_QDOC are always defined, making them equivalent. To avoid using different symbols, and the possible confusion and fragmentation that derives from it, all usages of Q_CLANG_QDOC are now replaced by the equivalent usages of Q_QDOC. Change-Id: I5810abb9ad1016a4c5bbea99acd03381b8514b3f Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* qthread.h: fix logic for Q_OS_FREEBSD and add support for 32bit FreeBSDTobias C. Berner2022-08-311-2/+2
| | | | | | | | | | | | | | | | | Fails to compile on i386 on FreeBSD with: In file included from /wrkdirs/usr/ports/devel/qt6-base/work/qtbase-everywhere-src-6.3.1/src/corelib/thread/qmutex.cpp:49: /wrkdirs/usr/ports/devel/qt6-base/work/qtbase-everywhere-src-6.3.1/src/corelib/thread/qthread.h:201:13: error: invalid operand for instruction __asm__("movq %%fs:%c1, %0" : "=r" (tid) : "i" (2 * sizeof(void*)) : ); ^ <inline asm>:1:14: note: instantiated into assembly here movq %fs:8, %edi ^~~~ 1 error generated. Pick-to: 6.2 6.3 6.4 Change-Id: I0a71e4631d7b6d452083d3ca8e35759e5dc563d4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QThread: re-fix currentThreadId() on LinuxThiago Macieira2022-05-041-2/+2
| | | | | | | | | | | | | | Commit 1808df9ce59a8c1d426f0361e25120a7852a6442 changed the Linux code to read the third field in the TCB header instead of the first, because that matches what FreeBSD does and what the documentation for the ABI appears to say. But it broke MUSL builds because they apparently don't obey the ABI. So don't use the inline code with libcs other than glibc. Pick-to: 6.2 6.3 Task-number: QTBUG-103000 Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16eba7748de50ddd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Mike Achtelik <mike.achtelik@gmail.com>
* QThread: Fix currentThreadId() on FreeBSDThiago Macieira2022-04-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We were reading from the wrong offset. It just happened to work on Linux because the values stored in the first and third fields of tcbhead_t[1] are the same. But that is not the case on FreeBSD for the same thing[2]. Confirmed by disassembly. Linux: Dump of assembler code for function __GI___pthread_self: 0x00007ffff71b6efe <+0>: endbr64 0x00007ffff71b6f02 <+4>: nop 0x00007ffff71b6f03 <+5>: nop 0x00007ffff71b6f04 <+6>: mov %fs:0x10,%rax 0x00007ffff71b6f0d <+15>: ret FreeBSD: (gdb) disass pthread_self Dump of assembler code for function _Tthr_self: 0x0000000800324790 <+0>: push %rbp 0x0000000800324791 <+1>: mov %rsp,%rbp 0x0000000800324794 <+4>: cmpq $0x0,0x8b1c(%rip) # 0x80032d2b8 <_thr_initial> 0x000000080032479c <+12>: jne 0x8003247a5 <_Tthr_self+21> 0x000000080032479e <+14>: xor %edi,%edi 0x00000008003247a0 <+16>: call 0x80031de40 <_libpthread_init> 0x00000008003247a5 <+21>: mov %fs:0x10,%rax 0x00000008003247ae <+30>: pop %rbp 0x00000008003247af <+31>: ret Also confirmed not to affect macOS: (lldb) disass -n pthread_self libsystem_pthread.dylib`pthread_self: libsystem_pthread.dylib[0x7ff80032186c] <+0>: pushq %rbp libsystem_pthread.dylib[0x7ff80032186d] <+1>: movq %rsp, %rbp libsystem_pthread.dylib[0x7ff800321870] <+4>: movq %gs:0x0, %rax [1] https://code.woboq.org/userspace/glibc/sysdeps/x86_64/nptl/tls.h.html#tcbhead_t [2] https://github.com/freebsd/freebsd-src/blob/main/sys/x86/include/tls.h#L43 Pick-to: 6.2 6.3 Fixes: QTBUG-103000 Change-Id: I7fb65b80b7844c8d8f26fffd16ea67d2f3461964 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* corelib: Fix typos in source code commentsJonas Kvinge2021-10-121-1/+1
| | | | | | Pick-to: 6.2 Change-Id: Ic78afb67143112468c6f84677ac88f27a74b53aa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* avoid max macro expansion on windows if NOMINMAX is missingAlexander Neumann2021-10-111-1/+1
| | | | | | Pick-to: 6.2 Change-Id: I1c19da59bdf97a434be52239c2a5b1b517341bcb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProperty: Only try to avoid TLS access if currentThreadId is fasterFabian Kosmale2021-08-041-0/+3
| | | | | | | | | | | We will not gain anything if we have to do multiple function calls to obtain the thread id. Therefore we introduce a macro to signal that we have a fast implementation of currentThreadId, and only use the function if it is defined. Pick-to: 6.2 Change-Id: I3347489ea91992896bb753b796ae26e391c2c99c Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Make the exit() methods in QEventLoop and QThread be slotsThiago Macieira2021-05-171-2/+1
| | | | | | | | | | | | | | | The documentation for QCoreApplication::exit() even refers to it as such. Instead of refactoring the documentation to explain that it isn't, just make it a slot and do the same for the other classes. Complements 2e6c37fe51b5f6073db0c7335c4a4272269d482f. [ChangeLog][QtCore][QEventLoop] exit() is now a slot, like quit(). [ChangeLog][QtCore][QThread] exit() is now a slot, like quit(). Change-Id: Ic42004c9bf71440eb433fffd167f4a1b89bcac80 Reviewed-by: David Faure <david.faure@kdab.com>
* Provide an inline implementation of currentThreadId() on WindowsLars Knoll2021-03-231-0/+25
| | | | | | | | | | | | | As this method is rather critical for performance of some central parts of Qt, it really should be inline whereever possible. This commit adds an inline implementation for Windows 32 and 64 bit. Amends 5e9b2ade678f37e43bfc2e3484f54cbbb5844d2e Change-Id: Iea51ef905b1cb7f91ca64b718d79bdc4f5c02c3a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> 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 one method as per ###Qt6Lars Knoll2020-09-121-2/+6
| | | | | | Change-Id: I4bf0ddf4ddf4044a60d881a57ef63b96d4bac262 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Sona Kurazyan <sona.kurazyan@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>
* QThread::create: remove the pre-C++17 codepathsGiuseppe D'Angelo2020-07-071-76/+3
| | | | | | | | | | | As we require C++17 now. The configure-time test checking for future/async is left in for the moment being. Change-Id: Ifde39d420673f70a2277f5a645bfaad30935a381 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-1/+1
| | | | | | | | | | | | | | | | | There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2019-11-251-4/+4
|\ | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qhash.h src/gui/kernel/qevent.h src/widgets/kernel/qshortcut.cpp src/widgets/kernel/qshortcut.h Change-Id: If61c206ee43ad1d97f5b07f58ac93c4583ce5620
| * Port QThread::wait() to QDeadlineTimerChristian Ehrlicher2019-11-131-4/+4
| | | | | | | | | | | | | | | | | | So we are in sync with QWaitCondition::wait(). Task-number: QTBUG-64266 Change-Id: I1d7487786513241cedd35d202c4ddee4937b08ec Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Read a unique thread identifier from CPU registersVolker Hilsheimer2019-10-201-0/+33
|/ | | | | | | | | | | | | | | | | | | | | | | | This is, depending on the implementation of pthread, significantly cheaper than using a pthread library call. Even if we don't know the assembler for an architecture, taking the address of the thread_local variable is still faster. As QThread::currentThreadId() is documented to be used internally and not meant for application code, we don't have to care about what exact value we return. Internally, we use it only to compare thread IDs for equality, which this implementation is sufficient for, even if a thread ID is re-used when one of the threads terminate and a new thread starts (since the other thread is still executing code). Besides, pthread_self documents [0] that a thread ID may be reused, and that the returned pthread_t cannot be portably compared using operator==(); using pthread_equal would require adding a Qt thread-ID type that implements this correctly, and would make things even slower. [0] http://man7.org/linux/man-pages/man3/pthread_self.3.html Change-Id: Id08e79b9b9c88976561f7cd36c66d43771fc4f24 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove handling of missing =delete and =default supportAllan Sandfeld Jensen2019-05-021-2/+0
| | | | | Change-Id: I006dfd0b7cfa3bda5e5ab01bcefa851f031dfe0e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_DECL_NOEXCEPT with noexcept in corelibAllan Sandfeld Jensen2019-04-031-2/+2
| | | | | | | In preparation of Qt6 move away from pre-C++11 macros. Change-Id: I44126693c20c18eca5620caab4f7e746218e0ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge QThread class definitionsMorten Johan Sørvig2018-08-171-31/+0
| | | | | | | | | We can reuse the main QThread definition for the no-thread configuration and avoid having to keep them in sync. Add stub definitions for member functions where needed. Change-Id: I128db11684a6040d09c4a4ce114f1399cba523f8 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Modernize the "thread" featureUlf Hermann2018-08-171-3/+3
| | | | | | | | | | Add it to configure.json and replace all occurrences of QT_NO_THREAD with QT_CONFIG(thread). Add conditions for other features that depend on thread support. Remove conditions where we can use the QMutex and QThreadStorage stubs. Change-Id: I284e5d794fda9a4c6f4a1ab29e55aa686272a0eb Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Make the stub implementation of QThread compile againUlf Hermann2018-06-221-0/+3
| | | | | | | | | | | | | | | | We cannot inline methods of QThreadPrivate because QThreadData has to be declared before. The global QThreadData needs to be accessible to QThreadData::clearCurrentThreadData(), and QAdoptedThread::run() has to be moved inside the #ifndef QT_NO_THREAD block as run() doesn't exist in the stub and Q_DECL_OVERRIDE would be wrong. We also fix the QThreadData::current() method to take and use the same parameters as in the non-stub case. Change-Id: Id29ca44b11fa95ed2df7cc39243a07ce7d3c455e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Make the sleep methods available in QThread even if QT_NO_THREADUlf Hermann2018-06-221-0/+4
| | | | | | | | | sleep, msleep, and usleep are not actually related to threading and serve a purpose also in a single threaded application. Change-Id: Iba2e343d48a9c09e60125bc1b589047e0241608a Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* doc: Fix all remaining non-link qdoc warningsMartin Smith2018-01-201-3/+3
| | | | | | | | | | | The fixes included adding missing '!' characters to qdoc comment markers, correct misspelled words, adding documentation for an anonymous enum type, and replacing Q_QDOC with Q_CLANG_QDOC. There remain 12 qdoc link warnings in QtBase. Change-Id: I00447722e6e029f5aed273b3cd571cef33c119b4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Merge remote-tracking branch 'origin/5.10' into devLiang Qi2017-10-171-21/+15
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: examples/network/fortuneclient/client.cpp examples/network/fortuneserver/server.cpp src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h src/plugins/platforms/cocoa/qcocoabackingstore.h src/plugins/platforms/cocoa/qcocoaintegration.h src/plugins/platforms/cocoa/qcocoascreen.h src/plugins/platforms/ios/qiosbackingstore.h src/plugins/sqldrivers/oci/qsql_oci.cpp src/widgets/kernel/qwidgetwindow.cpp Change-Id: Ia6dd2c52d4a691b671cf9a2ffca70deccece8f10
| * Move detection of <future> to a configure testGiuseppe D'Angelo2017-10-061-21/+15
| | | | | | | | | | | | | | | | | | | | | | <future> is needed by QThread::create. Instead of a fragile series of preprocessor tests, move its detection to a configure test. This dramatically simplifies the code, but on the other hand ties the availability of QThread::create() to the system used to compile Qt (rather the one used to compile an application). Change-Id: If1b06363379bf29126cfa68f2a0651cbb78a67f7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.10' into devLiang Qi2017-09-261-69/+59
|\| | | | | | | | | | | | | | | | | | | | | Conflicts: src/gui/kernel/qguiapplication.cpp src/platformsupport/input/libinput/qlibinputpointer.cpp src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h src/plugins/platforms/cocoa/qcocoawindow.h src/testlib/qtestsystem.h Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
| * QThread::create: move implementation out of lineGiuseppe D'Angelo2017-09-241-69/+52
| | | | | | | | | | | | | | | | | | | | | | Now that we accept STL datatypes in our ABI, expose a factory function that takes a std::future<void>, and hide the QThread subclass in our implementation. This also solves the problem of a non-exported polymorphic class that would generate duplicate vtables / typeinfo in all TUs. Change-Id: I70a5c301e7c589de1a4a189db39b86b956d1ba0d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
| * QThread::create: make qdoc generate its documentationGiuseppe D'Angelo2017-09-241-0/+7
| | | | | | | | | | Change-Id: I6eaaa0f9cbda6ef985cda63f2bf36d3102f34f32 Reviewed-by: Martin Smith <martin.smith@qt.io>
* | Replace Q_NULLPTR with nullptr where possibleKevin Funk2017-09-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Remaining uses of Q_NULLPTR are in: src/corelib/global/qcompilerdetection.h (definition and documentation of Q_NULLPTR) tests/manual/qcursor/qcursorhighdpi/main.cpp (a test executable compilable both under Qt4 and Qt5) Change-Id: If6b074d91486e9b784138f4514f5c6d072acda9a Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Replace Q_DECL_OVERRIDE with override where possibleKevin Funk2017-09-191-1/+1
|/ | | | | | | | | | | | | | | | Remaining uses of Q_DECL_OVERRIDE are in: src/corelib/global/qcompilerdetection.h src/corelib/global/qglobal.cpp doc/global/qt-cpp-defines.qdocconf (definition and documentation of Q_DECL_OVERRIDE) tests/manual/qcursor/qcursorhighdpi/main.cpp (a test executable compilable both under Qt4 and Qt5) Change-Id: Ib9b05d829add69e98a86238274b6a1fcb19b49ba Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QThread: Refine check for presence of std::futureFriedemann Kleint2017-05-291-2/+6
| | | | | | | | | | MinGW with win32 threads might not have _GLIBCXX_HAS_GTHREADS, so it needs to be checked. Amends change 597d4ff7962c0add87e4b93da4c366503d11aff5. Change-Id: I5c91d1dd3967c4922ced315b475d653b8b102ad6 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QThread: fix headersclean with C++17Marc Mutz2017-04-251-2/+2
| | | | | | | | | | GCC's -Wshadow complained about the re-use of 'args' as the parameter for the lambda. Fix by renaming it to largs (lambda-args) instead. Change-Id: Ia9e65b82b98ee56181d754868354988399496eef Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QThread: add static create functionGiuseppe D'Angelo2017-04-241-0/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the spirit of std::thread, which takes a function to call and its parameters, and runs it in a new thread. Since the user might want to connect to signals, move QObjects into the new thread, etc., the new thread is not immediately started. Although technically all of this _should_ be implementable in pure C++11, there is nothing in the Standard to help us not reinvent all the plumbing: packing the decay'd parameters, storing them, invoking the function over the parameters (honoring INVOKE/std::invoke semantics). std::function does not do the job, as it's copiable and therefore does not support move-only functors; std::bind does not have INVOKE semantics. I certainly do not want to reimplement all the required facilities inside of Qt. Therefore, the full blown implementation requires C++17 (std::invoke). In order to make this useful also in pre-C++17, there are two additional implementations (C++11 and C++14) that support just a callable, without any arguments passed to it. The C++11 implementation makes use of a class to store and call the callable (even move-only ones); basically, it's what a closure type for a C++14 lambda would look like. An alternative implementation could've used some of the existing facilities inside QObject::connect implementation that store a functor (for the connect() overload connecting to free functions), namely: the QtPrivate::QFunctorSlotObject class. However: * QFunctorSlotObject does not support move-only callables (see QTBUG-60339); * QFunctorSlotObject itself is not a callable (apparently by design), and requires to be wrapped in a lambda that calls call() on it; * the moment QTBUG-60339 is solved, we'd need the same handwritten closure to keep QFunctorSlotObject working with move-only callabes. So: just use the handwritten one. The C++14 implementation is a simplified version of the C++11 one, actually using a generalized lambda capture (corresponding to the handwritten C++11 closure type). All three implementations use std::async (with a deferred launch policy, a nice use case for it!) under the hood. It's certainly an overkill for our use case, as we don't need the std::future, but at least std::async does all the plumbing for us. [ChangeLog][QtCore][QThread] Added the QThread::create function. Change-Id: I339d0be6f689df7d56766839baebda0aa2f7e94c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Avoid zero-as-nullpointer warnings in QThreadUlf Hermann2017-01-041-2/+2
| | | | | | Change-Id: I3fd557a54d63c2dcabe58fab65326538896d02a2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Mark QThread::currentThreadId() as a pure functionThiago Macieira2016-05-081-1/+1
| | | | | | | | | | | It always returns the same information for each thread it is called in. But since it's different per thread, we don't think it's const. pthread_self() on Linux is marked const, though we think it really ought to be pure. On other OSes, the annotation isn't present, but the we can assume function is so. Change-Id: Ifea6e497f11a461db432ffff1448c2b37d94d5f3 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.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>
* QtCore: Use Q_NULLPTR instead of 0 in all public headersMarc Mutz2015-07-011-2/+2
| | | | | | | | | This is in preparation of adding -Wzero-as-null-pointer-constant (or similar) to the headers check. Task-number: QTBUG-45291 Change-Id: I0cc388ef9faf45cbcf425ad0dc77db3060c104a8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qdoc: Remove #ifdef Q_QDOC for uses of QPrivateSignalMartin Smith2015-04-201-10/+2
| | | | | | | | | | | | Signals marked with QPrivateSignal had the QPrivateSignal marker ifdefed out for qdoc. This is no longer necessary, so the #ifdefs are removed. Change-Id: Idb334ed311c6ed6883d7b7b5a3fcdede60c4a1f8 Task-number: QTBUG-45535 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Topi Reiniö <topi.reinio@digia.com>
* (Re)introduce loopLevel into QThreadAndy Shaw2015-03-091-0/+1
| | | | | | | | | | | This function used to reside in QEventLoop in Qt 3 and was deprecated in Qt 4. However this is useful for those who want to know how many event loops are running within the thread so we just make it possible to get at the already available variable. Change-Id: Ia6a7d94ff443a1d1577633363694bc2fa8eca7e4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jørgen Lind <jorgen.lind@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>
* Add Q_DECL_OVERRIDE in the src subdirectoryOlivier Goffart2014-12-031-1/+1
| | | | | | | | | | Done automatically with clang-modernize on linux (But does not add Q_DECL_OVERRIDE to the function that are marked as inline because it a compilation error with MSVC2010) Change-Id: I2196ee26e3e6fe20816834ecea5ea389eeab3171 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>