diff options
| author | Nick Mathewson <[email protected]> | 2016-01-22 16:17:34 -0500 |
|---|---|---|
| committer | Nick Mathewson <[email protected]> | 2016-02-19 13:25:31 -0500 |
| commit | 6186b3537e02b7b49a786529530f83ac151e7dbc (patch) | |
| tree | cd06f01b40f802445702361e643f165784e06ad6 | |
| parent | bafeec9c64b31f30635f38cfc672fe3727c1ed2b (diff) | |
Allow the user to disable interval support at compilation time
Some users only need plain timeouts. They shouldn't have to pay the
overhead for a field they will never set. With this patch, they can
define TIMEOUT_DISABLE_INTERVALS and turn off the feature at compile
time.
| -rw-r--r-- | timeout.c | 26 | ||||
| -rw-r--r-- | timeout.h | 4 |
2 files changed, 22 insertions, 8 deletions
@@ -44,6 +44,15 @@ #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 * @@ -337,20 +346,21 @@ static void timeouts_sched(struct timeouts *T, struct timeout *to, timeout_t exp static void timeouts_readd(struct timeouts *T, struct timeout *to) { - to->expires += to->interval; + const timeout_t interval = INTERVAL_GET(to); + to->expires += interval; if (to->expires <= T->curtime) { if (to->expires < T->curtime) { timeout_t n = T->curtime - to->expires; - timeout_t q = n / to->interval; - timeout_t r = n % to->interval; + timeout_t q = n / interval; + timeout_t r = n % interval; if (r) - to->expires += (to->interval * q) + (to->interval - r); + to->expires += (interval * q) + (interval - r); else - to->expires += (to->interval * q); + to->expires += (interval * q); } else { - to->expires += to->interval; + to->expires += interval; } } @@ -360,7 +370,7 @@ static void timeouts_readd(struct timeouts *T, struct timeout *to) { TIMEOUT_PUBLIC void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t timeout) { if (to->flags & TIMEOUT_INT) - to->interval = MAX(1, timeout); + INTERVAL_SET(to, MAX(1, timeout)); if (to->flags & TIMEOUT_ABS) timeouts_sched(T, to, timeout); @@ -529,7 +539,7 @@ TIMEOUT_PUBLIC struct timeout *timeouts_get(struct timeouts *T) { TAILQ_REMOVE(&T->expired, to, tqe); to->pending = 0; - if ((to->flags & TIMEOUT_INT) && to->interval > 0) { + if ((to->flags & TIMEOUT_INT) && INTERVAL_GET(to) > 0) { timeouts_readd(T, to); } else { to->timeouts = 0; @@ -99,7 +99,9 @@ struct timeout_cb { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#ifndef TIMEOUT_DISABLE_INTERVALS #define TIMEOUT_INT 0x01 /* interval (repeating) timeout */ +#endif #define TIMEOUT_ABS 0x02 /* treat timeout values as absolute */ #define TIMEOUT_INITIALIZER(flags) { (flags) } @@ -112,8 +114,10 @@ struct timeout_cb { struct timeout { int flags; +#ifndef TIMEOUT_DISABLE_INTERVALS timeout_t interval; /* timeout interval if periodic */ +#endif timeout_t expires; /* absolute expiration time */ |
