Commit ae78c6a9 authored by William Ahern's avatar William Ahern

reorder statements in timeouts_get to make TIMEOUT_DISABLE_INTERVALS case...

reorder statements in timeouts_get to make TIMEOUT_DISABLE_INTERVALS case simpler, removing need for macro accessors
parent 656c17be
...@@ -49,15 +49,6 @@ ...@@ -49,15 +49,6 @@
#define TO_SET_TIMEOUTS(to, T) ((to)->timeouts = (T)) #define TO_SET_TIMEOUTS(to, T) ((to)->timeouts = (T))
#endif #endif
#ifndef TIMEOUT_INT
#define TIMEOUT_INT 0
#define INTERVAL_GET(to) (abort(), 1)
#define INTERVAL_SET(to, val) abort()
#else
#define INTERVAL_GET(to) ((to)->interval)
#define INTERVAL_SET(to, val) ((to)->interval = (val))
#endif
/* /*
* A N C I L L A R Y R O U T I N E S * A N C I L L A R Y R O U T I N E S
* *
...@@ -274,8 +265,8 @@ static void timeouts_reset(struct timeouts *T) { ...@@ -274,8 +265,8 @@ static void timeouts_reset(struct timeouts *T) {
TAILQ_CONCAT(&reset, &T->expired, tqe); TAILQ_CONCAT(&reset, &T->expired, tqe);
TAILQ_FOREACH(to, &reset, tqe) { TAILQ_FOREACH(to, &reset, tqe) {
TO_SET_TIMEOUTS(to, NULL);
to->pending = NULL; to->pending = NULL;
TO_SET_TIMEOUTS(to, NULL);
} }
} /* timeouts_reset() */ } /* timeouts_reset() */
...@@ -362,32 +353,35 @@ static void timeouts_sched(struct timeouts *T, struct timeout *to, timeout_t exp ...@@ -362,32 +353,35 @@ static void timeouts_sched(struct timeouts *T, struct timeout *to, timeout_t exp
} /* timeouts_sched() */ } /* timeouts_sched() */
#ifndef TIMEOUT_DISABLE_INTERVALS
static void timeouts_readd(struct timeouts *T, struct timeout *to) { static void timeouts_readd(struct timeouts *T, struct timeout *to) {
const timeout_t interval = INTERVAL_GET(to); to->expires += to->interval;
to->expires += interval;
if (to->expires <= T->curtime) { if (to->expires <= T->curtime) {
if (to->expires < T->curtime) { if (to->expires < T->curtime) {
timeout_t n = T->curtime - to->expires; timeout_t n = T->curtime - to->expires;
timeout_t q = n / interval; timeout_t q = n / to->interval;
timeout_t r = n % interval; timeout_t r = n % to->interval;
if (r) if (r)
to->expires += (interval * q) + (interval - r); to->expires += (to->interval * q) + (to->interval - r);
else else
to->expires += (interval * q); to->expires += (to->interval * q);
} else { } else {
to->expires += interval; to->expires += to->interval;
} }
} }
timeouts_sched(T, to, to->expires); timeouts_sched(T, to, to->expires);
} /* timeouts_readd() */ } /* timeouts_readd() */
#endif
TIMEOUT_PUBLIC void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t timeout) { TIMEOUT_PUBLIC void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t timeout) {
#ifndef TIMEOUT_DISABLE_INTERVALS
if (to->flags & TIMEOUT_INT) if (to->flags & TIMEOUT_INT)
INTERVAL_SET(to, MAX(1, timeout)); to->interval = MAX(1, timeout);
#endif
if (to->flags & TIMEOUT_ABS) if (to->flags & TIMEOUT_ABS)
timeouts_sched(T, to, timeout); timeouts_sched(T, to, timeout);
...@@ -463,7 +457,7 @@ TIMEOUT_PUBLIC void timeouts_update(struct timeouts *T, abstime_t curtime) { ...@@ -463,7 +457,7 @@ TIMEOUT_PUBLIC void timeouts_update(struct timeouts *T, abstime_t curtime) {
struct timeout *to = TAILQ_FIRST(&todo); struct timeout *to = TAILQ_FIRST(&todo);
TAILQ_REMOVE(&todo, to, tqe); TAILQ_REMOVE(&todo, to, tqe);
to->pending = 0; to->pending = NULL;
timeouts_sched(T, to, to->expires); timeouts_sched(T, to, to->expires);
} }
...@@ -557,13 +551,13 @@ TIMEOUT_PUBLIC struct timeout *timeouts_get(struct timeouts *T) { ...@@ -557,13 +551,13 @@ TIMEOUT_PUBLIC struct timeout *timeouts_get(struct timeouts *T) {
struct timeout *to = TAILQ_FIRST(&T->expired); struct timeout *to = TAILQ_FIRST(&T->expired);
TAILQ_REMOVE(&T->expired, to, tqe); TAILQ_REMOVE(&T->expired, to, tqe);
to->pending = 0; to->pending = NULL;
TO_SET_TIMEOUTS(to, NULL);
if ((to->flags & TIMEOUT_INT) && INTERVAL_GET(to) > 0) { #ifndef TIMEOUT_DISABLE_INTERVALS
if ((to->flags & TIMEOUT_INT) && to->interval > 0)
timeouts_readd(T, to); timeouts_readd(T, to);
} else { #endif
TO_SET_TIMEOUTS(to, NULL);
}
return to; return to;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment