Commit 269e8df4 authored by William Ahern's avatar William Ahern

Merge branch 'optional_intervals'

parents 1aa993e3 ae78c6a9
...@@ -265,8 +265,8 @@ static void timeouts_reset(struct timeouts *T) { ...@@ -265,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() */
...@@ -353,6 +353,7 @@ static void timeouts_sched(struct timeouts *T, struct timeout *to, timeout_t exp ...@@ -353,6 +353,7 @@ 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) {
to->expires += to->interval; to->expires += to->interval;
...@@ -373,11 +374,14 @@ static void timeouts_readd(struct timeouts *T, struct timeout *to) { ...@@ -373,11 +374,14 @@ static void timeouts_readd(struct timeouts *T, struct timeout *to) {
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)
to->interval = 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);
...@@ -453,7 +457,7 @@ TIMEOUT_PUBLIC void timeouts_update(struct timeouts *T, abstime_t curtime) { ...@@ -453,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);
} }
...@@ -547,13 +551,13 @@ TIMEOUT_PUBLIC struct timeout *timeouts_get(struct timeouts *T) { ...@@ -547,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) && to->interval > 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 {
......
...@@ -100,7 +100,9 @@ struct timeout_cb { ...@@ -100,7 +100,9 @@ struct timeout_cb {
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef TIMEOUT_DISABLE_INTERVALS
#define TIMEOUT_INT 0x01 /* interval (repeating) timeout */ #define TIMEOUT_INT 0x01 /* interval (repeating) timeout */
#endif
#define TIMEOUT_ABS 0x02 /* treat timeout values as absolute */ #define TIMEOUT_ABS 0x02 /* treat timeout values as absolute */
#define TIMEOUT_INITIALIZER(flags) { (flags) } #define TIMEOUT_INITIALIZER(flags) { (flags) }
...@@ -113,8 +115,10 @@ struct timeout_cb { ...@@ -113,8 +115,10 @@ struct timeout_cb {
struct timeout { struct timeout {
int flags; int flags;
#ifndef TIMEOUT_DISABLE_INTERVALS
timeout_t interval; timeout_t interval;
/* timeout interval if periodic */ /* timeout interval if periodic */
#endif
timeout_t expires; timeout_t expires;
/* absolute expiration time */ /* absolute expiration time */
......
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