QTimerInfoList: improve class encapsulation
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>
This commit is contained in:
parent
48e06db2c5
commit
10575ffddb
@ -110,10 +110,7 @@ static gboolean timerSourceCheckHelper(GTimerSource *src)
|
||||
|| (src->processEventsFlags & QEventLoop::X11ExcludeTimers))
|
||||
return false;
|
||||
|
||||
if (src->timerList.updateCurrentTime() < src->timerList.constFirst()->timeout)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return !src->timerList.hasPendingTimers();
|
||||
}
|
||||
|
||||
static gboolean timerSourcePrepare(GSource *source, gint *timeout)
|
||||
|
@ -33,6 +33,19 @@ steady_clock::time_point QTimerInfoList::updateCurrentTime()
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
Updates the currentTime member to the current time, and returns \c true if
|
||||
the first timer's timeout is in the future (after currentTime).
|
||||
|
||||
The list is sorted by timeout, thus it's enough to check the first timer only.
|
||||
*/
|
||||
bool QTimerInfoList::hasPendingTimers()
|
||||
{
|
||||
if (isEmpty())
|
||||
return false;
|
||||
return updateCurrentTime() < constFirst()->timeout;
|
||||
}
|
||||
|
||||
/*
|
||||
insert timer info into list
|
||||
*/
|
||||
|
@ -43,7 +43,6 @@ public:
|
||||
QTimerInfoList();
|
||||
|
||||
std::chrono::steady_clock::time_point currentTime;
|
||||
std::chrono::steady_clock::time_point updateCurrentTime();
|
||||
|
||||
bool timerWait(timespec &);
|
||||
void timerInsert(QTimerInfo *);
|
||||
@ -59,12 +58,16 @@ public:
|
||||
QList<QAbstractEventDispatcher::TimerInfo> registeredTimers(QObject *object) const;
|
||||
|
||||
int activateTimers();
|
||||
bool hasPendingTimers();
|
||||
|
||||
QList::const_iterator findTimerById(int timerId) const
|
||||
{
|
||||
auto matchesId = [timerId](const QTimerInfo *t) { return t->id == timerId; };
|
||||
return std::find_if(cbegin(), cend(), matchesId);
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::steady_clock::time_point updateCurrentTime();
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user