diff options
| author | Nick Mathewson <[email protected]> | 2016-01-22 16:25:27 -0500 |
|---|---|---|
| committer | Nick Mathewson <[email protected]> | 2016-02-19 13:30:04 -0500 |
| commit | e7c5a9e08b206c97b1111eef8dcb03a19ee459ea (patch) | |
| tree | 8420370d506443dafcbceed7755af70d1a708000 | |
| parent | bafeec9c64b31f30635f38cfc672fe3727c1ed2b (diff) | |
Make the 'timeouts' field in struct timeout optional.
This field eats a pointer for every struct timeout, and it only
exists in order to enable a set of APIs that omit the 'struct
timeouts' object. For some applications, the convenience of these
APIs is not worth the memory overhead. This patch makes it so
that applications can disable those APIs, and save some memory, by
defining TIMEOUT_DISABLE_RELATIVE_ACCESS at compile time.
| -rw-r--r-- | timeout.c | 15 | ||||
| -rw-r--r-- | timeout.h | 5 |
2 files changed, 15 insertions, 5 deletions
@@ -43,6 +43,11 @@ #include "debug.h" #endif +#ifdef TIMEOUT_DISABLE_RELATIVE_ACCESS +#define TO_SET_TIMEOUTS(to, T) ((void)0) +#else +#define TO_SET_TIMEOUTS(to, T) ((to)->timeouts = (T)) +#endif /* * A N C I L L A R Y R O U T I N E S @@ -254,7 +259,7 @@ static void timeouts_reset(struct timeouts *T) { TAILQ_CONCAT(&reset, &T->expired, tqe); TAILQ_FOREACH(to, &reset, tqe) { - to->timeouts = NULL; + TO_SET_TIMEOUTS(to, NULL); to->pending = NULL; } } /* timeouts_reset() */ @@ -289,7 +294,7 @@ TIMEOUT_PUBLIC void timeouts_del(struct timeouts *T, struct timeout *to) { } to->pending = NULL; - to->timeouts = NULL; + TO_SET_TIMEOUTS(to, NULL); } } /* timeouts_del() */ @@ -317,7 +322,7 @@ static void timeouts_sched(struct timeouts *T, struct timeout *to, timeout_t exp to->expires = expires; - to->timeouts = T; + TO_SET_TIMEOUTS(to, T); if (expires > T->curtime) { rem = timeout_rem(T, to); @@ -532,7 +537,7 @@ TIMEOUT_PUBLIC struct timeout *timeouts_get(struct timeouts *T) { if ((to->flags & TIMEOUT_INT) && to->interval > 0) { timeouts_readd(T, to); } else { - to->timeouts = 0; + TO_SET_TIMEOUTS(to, NULL); } return to; @@ -618,6 +623,7 @@ TIMEOUT_PUBLIC struct timeout *timeout_init(struct timeout *to, int flags) { } /* timeout_init() */ +#ifndef TIMEOUT_DISABLE_RELATIVE_ACCESS TIMEOUT_PUBLIC bool timeout_pending(struct timeout *to) { return to->pending && to->pending != &to->timeouts->expired; } /* timeout_pending() */ @@ -631,6 +637,7 @@ TIMEOUT_PUBLIC bool timeout_expired(struct timeout *to) { TIMEOUT_PUBLIC void timeout_del(struct timeout *to) { timeouts_del(to->timeouts, to); } /* timeout_del() */ +#endif /* @@ -118,8 +118,10 @@ struct timeout { timeout_t expires; /* absolute expiration time */ +#ifndef TIMEOUT_DISABLE_RELATIVE_ACCESS struct timeouts *timeouts; /* timeouts collection if member of */ +#endif struct timeout_list *pending; /* timeout list if pending on wheel or expiry queue */ @@ -135,6 +137,7 @@ struct timeout { TIMEOUT_PUBLIC struct timeout *timeout_init(struct timeout *, int); /* initialize timeout structure (same as TIMEOUT_INITIALIZER) */ +#ifndef TIMEOUT_DISABLE_RELATIVE_ACCESS TIMEOUT_PUBLIC bool timeout_pending(struct timeout *); /* true if on timing wheel, false otherwise */ @@ -143,7 +146,7 @@ TIMEOUT_PUBLIC bool timeout_expired(struct timeout *); TIMEOUT_PUBLIC void timeout_del(struct timeout *); /* remove timeout from any timing wheel (okay if not member of any) */ - +#endif /* * T I M I N G W H E E L I N T E R F A C E S |
