Skip to content

Commit d581982

Browse files
committed
Simplify some code in TTimerQueue
1 parent df37994 commit d581982

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

source/tvision/ttimerqu.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
#define Uses_THardwareInfo
33
#include <tvision/tv.h>
44

5-
#if !defined( __BORLANDC__ )
6-
#include <chrono>
7-
#endif
8-
95
static TTimePoint systemTimeMs()
106
{
117
#if !defined( __FLAT__ )
@@ -80,6 +76,12 @@ void TTimerQueue::killTimer(TTimerId id)
8076
}
8177
}
8278

79+
static TTimePoint calcNextExpiresAt(TTimePoint expiresAt, TTimePoint now, int32_t period)
80+
// Pre: expiresAt <= now && period > 0.
81+
{
82+
return (1 + (now - expiresAt + period)/period)*period + expiresAt - period;
83+
}
84+
8385
void TTimerQueue::collectTimeouts(void (&func)(TTimerId, void *), void *args)
8486
{
8587
if (first == 0)
@@ -100,9 +102,7 @@ void TTimerQueue::collectTimeouts(void (&func)(TTimerId, void *), void *args)
100102
{
101103
(*p)->collectId = collectId;
102104
if ((*p)->period > 0)
103-
(*p)->expiresAt =
104-
(1 + (now - (*p)->expiresAt + (*p)->period)/(*p)->period)*(*p)->period +
105-
(*p)->expiresAt - (*p)->period;
105+
(*p)->expiresAt = calcNextExpiresAt((*p)->expiresAt, now, (*p)->period);
106106
}
107107
else // One-shot timer
108108
{

0 commit comments

Comments
 (0)