mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Use RelativeTime from startup in DeadlineTimer
This commit is contained in:
@@ -42,7 +42,8 @@ public:
|
|||||||
// Okay to call on an active timer.
|
// Okay to call on an active timer.
|
||||||
// However, an extra notification may still happen due to concurrency.
|
// However, an extra notification may still happen due to concurrency.
|
||||||
//
|
//
|
||||||
void activate (DeadlineTimer& timer, double secondsRecurring, Time const& when)
|
void activate (DeadlineTimer& timer,
|
||||||
|
double secondsRecurring, RelativeTime const& when)
|
||||||
{
|
{
|
||||||
bassert (secondsRecurring >= 0);
|
bassert (secondsRecurring >= 0);
|
||||||
|
|
||||||
@@ -85,7 +86,8 @@ public:
|
|||||||
{
|
{
|
||||||
while (! threadShouldExit ())
|
while (! threadShouldExit ())
|
||||||
{
|
{
|
||||||
Time const currentTime = Time::getCurrentTime ();
|
RelativeTime const currentTime (
|
||||||
|
RelativeTime::fromStartup ());
|
||||||
|
|
||||||
double seconds (0);
|
double seconds (0);
|
||||||
DeadlineTimer* timer (nullptr);
|
DeadlineTimer* timer (nullptr);
|
||||||
@@ -110,7 +112,7 @@ public:
|
|||||||
{
|
{
|
||||||
// Yes so set the timer again.
|
// Yes so set the timer again.
|
||||||
timer->m_notificationTime =
|
timer->m_notificationTime =
|
||||||
currentTime + RelativeTime (timer->m_secondsRecurring);
|
currentTime + timer->m_secondsRecurring;
|
||||||
|
|
||||||
// Put it back into the list as active
|
// Put it back into the list as active
|
||||||
insertSorted (*timer);
|
insertSorted (*timer);
|
||||||
@@ -224,7 +226,8 @@ void DeadlineTimer::setExpiration (double secondsUntilDeadline)
|
|||||||
{
|
{
|
||||||
bassert (secondsUntilDeadline != 0);
|
bassert (secondsUntilDeadline != 0);
|
||||||
|
|
||||||
Time const when = Time::getCurrentTime () + RelativeTime (secondsUntilDeadline);
|
RelativeTime const when (
|
||||||
|
RelativeTime::fromStartup() + secondsUntilDeadline);
|
||||||
|
|
||||||
m_manager->activate (*this, 0, when);
|
m_manager->activate (*this, 0, when);
|
||||||
}
|
}
|
||||||
@@ -233,13 +236,8 @@ void DeadlineTimer::setRecurringExpiration (double secondsUntilDeadline)
|
|||||||
{
|
{
|
||||||
bassert (secondsUntilDeadline != 0);
|
bassert (secondsUntilDeadline != 0);
|
||||||
|
|
||||||
Time const when = Time::getCurrentTime () + RelativeTime (secondsUntilDeadline);
|
RelativeTime const when (
|
||||||
|
RelativeTime::fromStartup() + secondsUntilDeadline);
|
||||||
|
|
||||||
m_manager->activate (*this, secondsUntilDeadline, when);
|
m_manager->activate (*this, secondsUntilDeadline, when);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeadlineTimer::setExpirationTime (Time const& when)
|
|
||||||
{
|
|
||||||
m_manager->activate (*this, 0, when);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void cancel ();
|
void cancel ();
|
||||||
|
|
||||||
|
|
||||||
/** Set the timer to go off once in the future.
|
/** Set the timer to go off once in the future.
|
||||||
If the timer is already active, this will reset it.
|
If the timer is already active, this will reset it.
|
||||||
@note If the timer is already active, the old one might go off
|
@note If the timer is already active, the old one might go off
|
||||||
@@ -73,15 +72,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setRecurringExpiration (double secondsUntilDeadline);
|
void setRecurringExpiration (double secondsUntilDeadline);
|
||||||
|
|
||||||
/** Set the timer to go off at a specific time.
|
|
||||||
If the timer is already active, this will reset it.
|
|
||||||
@note If the timer is already active, the old one might go off
|
|
||||||
before this function returns.
|
|
||||||
@note If the time is in the past, the timer will go off
|
|
||||||
immediately.
|
|
||||||
*/
|
|
||||||
void setExpirationTime (Time const& when);
|
|
||||||
|
|
||||||
/** Equality comparison.
|
/** Equality comparison.
|
||||||
Timers are equal if they have the same address.
|
Timers are equal if they have the same address.
|
||||||
*/
|
*/
|
||||||
@@ -102,7 +92,7 @@ private:
|
|||||||
Listener* const m_listener;
|
Listener* const m_listener;
|
||||||
SharedPtr <SharedSingleton <Manager> > m_manager;
|
SharedPtr <SharedSingleton <Manager> > m_manager;
|
||||||
bool m_isActive;
|
bool m_isActive;
|
||||||
Time m_notificationTime;
|
RelativeTime m_notificationTime;
|
||||||
double m_secondsRecurring; // non zero if recurring
|
double m_secondsRecurring; // non zero if recurring
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user