summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-02-18 21:09:59 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-03-13 17:29:13 -0800
commit1ca89b65d85c5df971fac7c1f9d5678e0e0cf45b (patch)
treee08df46eb5d1cc592fa25101bb2c9226c103717f /src/corelib/kernel
parentafa86c60e6b6513c5c34b3832a5ece526c071c3f (diff)
QAbstractEventDispatcher: port timer uses to the V2 API
Change-Id: I83dda2d36c904517b3c0fffd17b52b71739928dc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qbasictimer.cpp4
-rw-r--r--src/corelib/kernel/qchronotimer.cpp2
-rw-r--r--src/corelib/kernel/qobject.cpp11
-rw-r--r--src/corelib/kernel/qtimer.cpp4
4 files changed, 11 insertions, 10 deletions
diff --git a/src/corelib/kernel/qbasictimer.cpp b/src/corelib/kernel/qbasictimer.cpp
index e7626f74263..17711a355e6 100644
--- a/src/corelib/kernel/qbasictimer.cpp
+++ b/src/corelib/kernel/qbasictimer.cpp
@@ -165,7 +165,7 @@ void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerT
}
stop();
if (obj)
- id = eventDispatcher->registerTimer(duration.count(), timerType, obj);
+ id = int(eventDispatcher->registerTimer(duration, timerType, obj));
}
/*!
@@ -177,7 +177,7 @@ void QBasicTimer::stop()
{
if (id) {
QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
- if (eventDispatcher && !eventDispatcher->unregisterTimer(id)) {
+ if (eventDispatcher && !eventDispatcher->unregisterTimer(Qt::TimerId(id))) {
qWarning("QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
return;
}
diff --git a/src/corelib/kernel/qchronotimer.cpp b/src/corelib/kernel/qchronotimer.cpp
index 4da75382782..a517c4446b4 100644
--- a/src/corelib/kernel/qchronotimer.cpp
+++ b/src/corelib/kernel/qchronotimer.cpp
@@ -330,7 +330,7 @@ QBindable<std::chrono::nanoseconds> QChronoTimer::bindableInterval()
std::chrono::nanoseconds QChronoTimer::remainingTime() const
{
if (isActive())
- return 1ms * QAbstractEventDispatcher::instance()->remainingTime(qToUnderlying(d_func()->id));
+ return QAbstractEventDispatcher::instance()->remainingTime(d_func()->id);
return std::chrono::nanoseconds::min();
}
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 162420532ff..dba3529b947 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1453,7 +1453,7 @@ bool QObject::event(QEvent *e)
QThreadData *threadData = d->threadData.loadRelaxed();
QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher.loadRelaxed();
if (eventDispatcher) {
- QList<QAbstractEventDispatcher::TimerInfo> timers = eventDispatcher->registeredTimers(this);
+ QList<QAbstractEventDispatcher::TimerInfoV2> timers = eventDispatcher->timersForObject(this);
if (!timers.isEmpty()) {
const bool res = eventDispatcher->unregisterTimers(this);
// do not to release our timer ids back to the pool (since the timer ids are moving to a new thread).
@@ -1920,11 +1920,10 @@ int QObject::startTimer(std::chrono::nanoseconds interval, Qt::TimerType timerTy
}
auto dispatcher = thisThreadData->eventDispatcher.loadRelaxed();
- const auto msecs = std::chrono::ceil<std::chrono::milliseconds>(interval);
- int timerId = dispatcher->registerTimer(msecs.count(), timerType, this);
+ Qt::TimerId timerId = dispatcher->registerTimer(interval, timerType, this);
d->ensureExtraData();
- d->extraData->runningTimers.append(Qt::TimerId{timerId});
- return timerId;
+ d->extraData->runningTimers.append(timerId);
+ return int(timerId);
}
/*!
@@ -1966,7 +1965,7 @@ void QObject::killTimer(Qt::TimerId id)
auto thisThreadData = d->threadData.loadRelaxed();
if (thisThreadData->hasEventDispatcher())
- thisThreadData->eventDispatcher.loadRelaxed()->unregisterTimer(qToUnderlying(id));
+ thisThreadData->eventDispatcher.loadRelaxed()->unregisterTimer(id);
d->extraData->runningTimers.remove(at);
QAbstractEventDispatcherPrivate::releaseTimerId(id);
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index 3291c7d24bf..cc46c1433b5 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -632,7 +632,9 @@ int QTimer::remainingTime() const
{
Q_D(const QTimer);
if (d->isActive()) {
- return QAbstractEventDispatcher::instance()->remainingTime(qToUnderlying(d->id));
+ using namespace std::chrono;
+ auto remaining = QAbstractEventDispatcher::instance()->remainingTime(d->id);
+ return ceil<milliseconds>(remaining).count();
}
return -1;