summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtimerinfo_unix_p.h
Commit message (Collapse)AuthorAgeFilesLines
* QEventDispatcher*: port the Unix dispatchers to V2Thiago Macieira2024-03-131-12/+11
| | | | | | | | | | | They're all ported in one go because all the changes are the same and they all rely on QTimerInfoList. The changes are: - use Qt::TimerId to uniquely identify timer IDs - use Duration (nanoseconds) to specify the timer interval - rename registeredTimers() to timersForObject(), which is const Change-Id: I83dda2d36c904517b3c0fffd17b52958767d8a68 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QTimerInfo: store nanoseconds instead of millisecondsThiago Macieira2024-03-131-8/+12
| | | | | | | | | | | | | | No change in behavior, other than the ability for the precise timers to be even more precise. There's a reduction in the stored interval range from 292 million years to 292 years, but there's no change in behavior because the timeout is stored as a steady_clock::time_point, which is nanoseconds with libstdc++ and libc++. Now, if there's an overflow, it'll happen on the call to registerTimer() instead of inside the calculation of the wake-up. Change-Id: I83dda2d36c904517b3c0fffd17b3d1f2d9505c1c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QTimerInfoList: change timerWait() to return std::optional<ms>Ahmad Samir2023-08-111-1/+1
| | | | | | | | | | | | | QEventDispatcherGlib: it used the out-parameter timespec to set a timeout in milliseconds, making timerWait() return milliseconds is more straightforward. Also timerWait() returns the time rounded to milliseconds, so the code in QEventDispatcherGlib that rounded up the timespec::tv_nsec part was no-op, tv_nsec was always 0 IIUC. In QEventDispatcherGlib, guard against overflow with qt_saturate. Change-Id: Ie6f78374d00cbe8a6adf7b50ed67c8c86ab4d29d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfo: refactor QTimerInfoAhmad Samir2023-07-191-5/+10
| | | | | | | | | | - Add a constructor - Initialize members in-class - Reorder the data members so as not to waste space between them, now all the padding is at the end Change-Id: Ic88200fbff049615a6a43e322e724cf619fc3cdb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfoList: don't inherit from a container in an exported classAhmad Samir2023-07-191-7/+18
| | | | | | | | | | | | | | | | | | | Instead use composition by using a container member; inheriting from containers has a couple of issues: - containers (STL and Qt) don't have virtual destructors, which means that deleting via a pointer to the base-class would be troublesome - as it turns out, inheriting from containers, QList in this case, in an exported derived-class could lead to binary-incompatibility issues (see linked bug report) Drive-by change: - group all private members in one place - make timerInsert() private, nothing should use it from outside the class anyway Change-Id: I69843835d8c854fa4b13e8b4ba3fb69f1484f6a6 Fixes: QTBUG-111959 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfoList: improve class encapsulationAhmad Samir2023-06-101-1/+4
| | | | | | | | | Replace the only usage of updateCurrentTime() outside of the class by a getter that checks if there are pending timers. And make updateCurrentTime() private. Change-Id: I148639b01abd75990cfc7b25bb1f466e45ab0c71 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfoList: cleanupAhmad Samir2023-06-101-12/+2
| | | | | | | | | | - Initialize member in-class - Remove redundant include - Remove QTIMERINFO_DEBUG related code, it hasn't been compiled for a long time, so it has bit-rotted, and its purpose isn't clear any more Change-Id: I874415e1edec7c4da03f697f5f9f8665d8b015a3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfoList/Unix: use chrono::steady_clock::time_pointAhmad Samir2023-06-101-3/+4
| | | | | | | | I.e. use chrono first, see linked task for more details. Task-number: QTBUG-110059 Change-Id: Ie0908f9446957d4383fb7a70b67c16b78605a0f3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfoList: remove code that attempted to repair time on clock jumpsThiago Macieira2023-04-181-13/+0
| | | | | | | | | We only use monotonic clocks now (std::chrono::steady_clock). This probably didn't work very well anyway. Change-Id: Ieec322d73c1e40ad95c8fffd17465f06b5b2816f Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definitionEdward Welbourne2023-03-201-1/+1
| | | | | | | | | | 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>
* QTimerInfo: use range-for; use STL algorithmsAhmad Samir2023-02-241-0/+6
| | | | | | Change-Id: I7e1b603540a2a2b4d1b12d4dbdba7e9183ee367f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
* QTimerInfo: use chrono for time intervalsAhmad Samir2023-02-241-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For VeryCoarseTimer: - The code used to convert QTimerInfo::interval to seconds in registerTimer(), then convert to milliseconds when creating QTimerInfo in registeredTimers(); this is a bit confusing as "interval" was sometimes milliseconds and sometimes seconds depending on the type of the timer; instead "round" to the nearest second while always keeping "interval" in milliseconds (relying on chrono doing the conversion).. - Add roundToSecs() helper; it behaves like the original code (i.e. rounding each 500ms to 1 full second): const auto list = {300, 499, 500, 600, 1000, 1300, 1499, 1500, 1501, 1600, 2000, 2300, 2499, 2500, 2600}; using namespace std::chrono; for (int dur : list) { auto i = dur; i /= 500; i += 1; i >>= 1; // Original code milliseconds msec{dur}; seconds secs = duration_cast<seconds>(msec); milliseconds frac = msec - secs; if (frac >= 500ms) secs += 1s; assert(i == secs.count()); } ---- - Don't mix signed and unsigned when doing arithmetic The next "chrono-first" step would be changing QAbstractEventDispatcher::TimerInfo::interval from int to chrono::milliseconds, and adding a virtual QAbstractEventDispatcher::registerTimer() overload that takes chrono::milliseconds; neither can be done until Qt7 due to binary compatibility constraints, c.f.: https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C++ Task-number: QTBUG-110059 Change-Id: I36f9bd8fb29565b1131afb3cdfc313452f625598 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfo: add missing qplatformdefs.h includeAhmad Samir2023-02-171-0/+2
| | | | | Change-Id: I74b5b5cfe0257d980b600bc1a61b656fea9770df Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfo: re-pack the membersGiuseppe D'Angelo2023-01-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 0148c6925ec3b6b9a9d2f57ae44fea292a6625e1 added support for qint64 intervals in the abstract dispatcher. Changing the `int` interval to `qint64` causes padding in the QTimerInfo struct. On X86-64: struct TimerInfo { int id; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ qint64 interval; /* 8 8 */ enum TimerType timerType; /* 16 4 */ /* XXX 4 bytes hole, try to pack */ struct timespec timeout; /* 24 16 */ class QObject * obj; /* 40 8 */ class QTimerInfo * * activateRef; /* 48 8 */ /* size: 56, cachelines: 1, members: 6 */ /* sum members: 48, holes: 2, sum holes: 8 */ /* last cacheline: 56 bytes */ }; On ARM32: struct TimerInfo { int id; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ qint64 interval; /* 8 8 */ enum TimerType timerType; /* 16 4 */ struct timespec timeout; /* 20 8 */ class QObject * obj; /* 28 4 */ class QTimerInfo * * activateRef; /* 32 4 */ /* size: 40, cachelines: 1, members: 6 */ /* sum members: 32, holes: 1, sum holes: 4 */ /* padding: 4 */ /* last cacheline: 40 bytes */ }; Change the order of the members, so we remove the padding: struct TimerInfo { int id; /* 0 4 */ enum TimerType timerType; /* 4 4 */ qint64 interval; /* 8 8 */ struct timespec timeout; /* 16 16 */ class QObject * obj; /* 32 8 */ class QTimerInfo * * activateRef; /* 40 8 */ /* size: 48, cachelines: 1, members: 6 */ /* last cacheline: 48 bytes */ }; Pick-to: 6.5 Change-Id: Ia1cc56e497f87611fa411a19361f8ebb13ff1f67 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Migrate QBasicTimer from int to qint64Konrad Kujawa2022-08-301-1/+1
| | | | | | | QBasicTimer::start() now accepts qint64 instead of int. Change-Id: Iba3f394b6c20daf762f1add5a9eed22c8a67c802 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | 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>
* QAbstractEventDispatcher: change event dispatcher timer interval to qint64Liu Yang2020-09-211-2/+2
| | | | | | | | | Resolve remaining Qt6 TODO [ChangeLog][QtCore][QAbstractEventDispatcher] The signature of the abstract virtual registerTime function now takes a qint64 value for the interval parameter. Change-Id: I10166ad5cfb455edc404d465a3731ff094a8977e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Make sure all private headers in Qt Core include qglobal_p.hThiago Macieira2016-06-251-0/+2
| | | | | | | | | | | | The rule was: - if the header included qglobal.h, turn that into qglobal_p.h - otherwise, insert the #include after the "We mean it" warning qglobal_p.h currently only includes qglobal.h. Change-Id: Ib056b47dde3341ef9a52ffff13ef677e471674b7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Switch to struct timespec everywhere instead of timevalThiago Macieira2013-01-281-7/+7
| | | | | | | | | | | | This avoids an extra division by 1000 when getting the current time. This can't overflow, under normal circumstances, even on 32-bit: when adding two values less than 1 billion, the result is less than 2 billion, which is less than 2^31. Change-Id: I6f8e1aadfe2fcf6ac8da584eab4c1e61aee51cbb Reviewed-by: David Faure (KDE) <faure@kde.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Add a remainingTime() method to the public interface of the QTimer classLaszlo Papp2012-04-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It is an extension coming from the use case when you, for instance, need to implement a countdown timer in client codes, and manually maintain a dedicated variable for counting down with the help of yet another Timer. There might be other use cases as well. The returned value is meant to be in milliseconds, as the method documentation says, since it is reasonable, and consistent with the rest (ie. the interval accessor). The elapsed time is already being tracked inside the event dispatcher, thus the effort is only exposing that for all platforms supported according to the desired timer identifier, and propagating up to the QTimer public API. It is done by using the QTimerInfoList class in the glib and unix dispatchers, and the WinTimeInfo struct for the windows dispatcher. It might be a good idea to to establish a QWinTimerInfo (qtimerinfo_win{_p.h,cpp}) in the future for resembling the interface for windows with the glib/unix management so that it would be consistent. That would mean abstracting out a base class (~interface) for the timer info classes. Something like that QAbstractTimerInfo. Test: Build test only on (Arch)Linux, Windows and Mac. I have also run the unit tests and they passed as well. Change-Id: Ie37b3aff909313ebc92e511e27d029abb070f110 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Export QTimerInfoListBradley T. Hughes2012-01-091-1/+1
| | | | | | | | | ... so that QCocoaEventDispatcher can use it to implement timer handling and benefit from the Qt::TimerType support in QTimerInfoList. Change-Id: I34b81502465963e2c9d528df463fa2eccd275ad6 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimerInfo::expected is only needed for debuggingBradley T. Hughes2012-01-061-1/+1
| | | | | | | | | The code for calculating the expected time is only useful for debugging purposes. Don't compile this into the library unless QTIMERINFO_DEBUG is defined. Change-Id: I6530e6a70410a12544410ef286225df98ceddcee Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Do not always compile in QTimerInfoList::repairTimers()Bradley T. Hughes2012-01-051-1/+1
| | | | | | | | | | | | This function is never called on systems that are guaranteed to have a monotonic click (like Mac OS X). Remove the dead code from the library. Change-Id: I95852c8dffaa3a9747367f0abe4a4c62e4f86421 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Use Qt::TimerType on UNIX when scheduling timersBradley T. Hughes2012-01-051-1/+9
| | | | | | | | | | | | | | | | As stated in the documentation for Qt::TimerType, we allow for up to 5% error for CoarseTimers (the default timer type). PreciseTimers are not adjusted at all, and VeryCoarseTimers fire with one-second accuracy. The objective is to make most timers wake up at the same time, thereby reducing CPU wakeups. Note that this changes makes it possible for timers to fire early, which may be unexpected for some applications. Such applications should use PreciseTimers explicitly. Author: Thiago Macieira <thiago.macieira@nokia.com> Change-Id: Iaa70314c39a446adbc6dbb6fdfa7bafcd98a7283 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Change QTimerInfo (UNIX) to keep the interval in milliseconds.Bradley T. Hughes2012-01-021-1/+1
| | | | | | | | | | The API passes the interval as an int, there's no reason to convert it to a timeval struct. This also prepares for changing the UNIX timer code to support the different timer types. Author: Thiago Macieira <thiago.macieira@nokia.com> Change-Id: Ie3cc1ae8f1be6a9ad3f1766051642cbf3e614418 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add Qt::TimerType argument to QAbstractEventDispatcher::registerTimer()Bradley T. Hughes2012-01-021-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | ... and deprecate the old registerTimer() functions. The new pure- virtual registerTimer() breaks source-compatibility. Subclasses cannot be instantiated anymore, since the pure virtual function signature has changed. QAbstractEventDispatcher::TimerInfo is no longer a QPair. It is now a struct with timerId, interval, and timerType members. This is a source incompatibility that should only affect subclasses of QAbstractEventDispatcher, which will need to pass 3 arguments to the TimerInfo constructor instead of 2. If the subclass used QPair<int,int> instead of the TimerInfo typedef, the QPair<int,int> declarations will need to be replaced with TimerInfo. Call the new registerTimer() function with the type from QObject::startTimer(). Change all subclasses of QAbstractEventDispatcher to reimplement the new virtual function. The type argument is unused at the momemnt, except to ensure that registeredTimers() returns the type each timer was registered with. Implementations for the various dispatchers will be done in separate commits. Author: Thiago Macieira <thiago.macieira@nokia.com> Change-Id: Ia22697e0ab0847810c5d162ef473e0e5a17a904b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Split timer handling out of QEventDispatcherUnix.Robin Burchell2011-12-151-0/+110
This makes it easier to see the guts of the unix event dispatcher, and to experiment with it. Change-Id: I715bb68c4de6798e10bc55304a128b88e0249c63 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>