When adjusting timer::rest, round to the closest TICKUNIT usecs
value. This has minimal impact here, but if ppp ever needs to frequently remove timers before they've timed out, it can badly skew the next item in the timer list without this change. The correct fix would be to store usecs in `rest' rather than TICKUNITs, but the math is easier if we just round...
This commit is contained in:
parent
e722aa17f8
commit
76ce2d4bcb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=58030
@ -35,6 +35,11 @@
|
||||
#include "descriptor.h"
|
||||
#include "prompt.h"
|
||||
|
||||
|
||||
#define RESTVAL(t) \
|
||||
((t).it_value.tv_sec * SECTICKS + (t).it_value.tv_usec / TICKUNIT + \
|
||||
((((t).it_value.tv_usec % TICKUNIT) >= (TICKUNIT >> 1)) ? 1 : 0))
|
||||
|
||||
static struct pppTimer *TimerList = NULL, *ExpiredList = NULL;
|
||||
|
||||
static void StopTimerNoBlock(struct pppTimer *);
|
||||
@ -80,8 +85,7 @@ timer_Start(struct pppTimer *tp)
|
||||
|
||||
/* Adjust our first delta so that it reflects what's really happening */
|
||||
if (TimerList && getitimer(ITIMER_REAL, &itimer) == 0)
|
||||
TimerList->rest = itimer.it_value.tv_sec * SECTICKS +
|
||||
itimer.it_value.tv_usec / TICKUNIT;
|
||||
TimerList->rest = RESTVAL(itimer);
|
||||
|
||||
pt = NULL;
|
||||
for (t = TimerList; t; t = t->next) {
|
||||
@ -145,8 +149,7 @@ StopTimerNoBlock(struct pppTimer *tp)
|
||||
struct itimerval itimer;
|
||||
|
||||
if (getitimer(ITIMER_REAL, &itimer) == 0)
|
||||
t->rest = itimer.it_value.tv_sec * SECTICKS +
|
||||
itimer.it_value.tv_usec / TICKUNIT;
|
||||
t->rest = RESTVAL(itimer);
|
||||
}
|
||||
t->next->rest += t->rest;
|
||||
if (!pt) /* t->next is now the first in the list */
|
||||
@ -225,8 +228,7 @@ timer_Show(int LogLevel, struct prompt *prompt)
|
||||
|
||||
/* Adjust our first delta so that it reflects what's really happening */
|
||||
if (TimerList && getitimer(ITIMER_REAL, &itimer) == 0)
|
||||
TimerList->rest = itimer.it_value.tv_sec * SECTICKS +
|
||||
itimer.it_value.tv_usec / TICKUNIT;
|
||||
TimerList->rest = RESTVAL(itimer);
|
||||
|
||||
#define SECS(val) ((val) / SECTICKS)
|
||||
#define HSECS(val) (((val) % SECTICKS) * 100 / SECTICKS)
|
||||
|
Loading…
Reference in New Issue
Block a user