Commit 54e4bc4d authored by William Ahern's avatar William Ahern

move compile time-optional members to end of timeout structure

rename timeouts_cursor to more terse timeouts_it
bumb version numbers
parent 269e8df4
......@@ -57,8 +57,8 @@ static int empty(void *T) {
} /* empty() */
static struct timeout *next(void *T, struct timeouts_cursor *cur) {
return timeouts_next(T, cur);
static struct timeout *next(void *T, struct timeouts_it *it) {
return timeouts_next(T, it);
} /* next() */
......
......@@ -185,10 +185,10 @@ static int bench_empty(lua_State *L) {
static int bench__next(lua_State *L) {
struct bench *B = lua_touserdata(L, lua_upvalueindex(1));
struct timeouts_cursor *cursor = lua_touserdata(L, lua_upvalueindex(2));
struct timeouts_it *it = lua_touserdata(L, lua_upvalueindex(2));
struct timeout *to;
if (!B->ops.next || !(to = B->ops.next(B->state, cursor)))
if (!B->ops.next || !(to = B->ops.next(B->state, it)))
return 0;
lua_pushinteger(L, luaL_optinteger(L, 2, 0) + 1);
......@@ -201,12 +201,12 @@ static int bench__next(lua_State *L) {
} /* bench__next() */
static int bench__pairs(lua_State *L) {
struct timeouts_cursor *cursor;
struct timeouts_it *it;
lua_settop(L, 1);
cursor = lua_newuserdata(L, sizeof *cursor);
TIMEOUTS_CURSOR_INIT(cursor, TIMEOUTS_ALL);
it = lua_newuserdata(L, sizeof *it);
TIMEOUTS_IT_INIT(it, TIMEOUTS_ALL);
lua_pushcclosure(L, &bench__next, 2);
lua_pushvalue(L, 1);
......
......@@ -6,6 +6,6 @@ struct benchops {
void (*update)(void *, timeout_t);
void (*check)(void *);
int (*empty)(void *);
struct timeout *(*next)(void *, struct timeouts_cursor *);
struct timeout *(*next)(void *, struct timeouts_it *);
void (*destroy)(void *);
}; /* struct benchops() */
......@@ -631,12 +631,12 @@ TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *T, FILE *fp) {
#define ENTER \
do { \
static const int pc0 = __LINE__; \
switch (pc0 + cur->pc) { \
switch (pc0 + it->pc) { \
case __LINE__: (void)0
#define SAVE_AND_DO(do_statement) \
do { \
cur->pc = __LINE__ - pc0; \
it->pc = __LINE__ - pc0; \
do_statement; \
case __LINE__: (void)0; \
} while (0)
......@@ -649,21 +649,21 @@ TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *T, FILE *fp) {
} \
} while (0)
TIMEOUT_PUBLIC struct timeout *timeouts_next(struct timeouts *T, struct timeouts_cursor *cur) {
TIMEOUT_PUBLIC struct timeout *timeouts_next(struct timeouts *T, struct timeouts_it *it) {
struct timeout *to;
ENTER;
if (cur->flags & TIMEOUTS_EXPIRED) {
TAILQ_FOREACH_SAFE(to, &T->expired, tqe, cur->to) {
if (it->flags & TIMEOUTS_EXPIRED) {
TAILQ_FOREACH_SAFE(to, &T->expired, tqe, it->to) {
YIELD(to);
}
}
if (cur->flags & TIMEOUTS_PENDING) {
for (cur->i = 0; cur->i < countof(T->wheel); cur->i++) {
for (cur->j = 0; cur->j < countof(T->wheel[cur->i]); cur->j++) {
TAILQ_FOREACH_SAFE(to, &T->wheel[cur->i][cur->j], tqe, cur->to) {
if (it->flags & TIMEOUTS_PENDING) {
for (it->i = 0; it->i < countof(T->wheel); it->i++) {
for (it->j = 0; it->j < countof(T->wheel[it->i]); it->j++) {
TAILQ_FOREACH_SAFE(to, &T->wheel[it->i][it->j], tqe, it->to) {
YIELD(to);
}
}
......
......@@ -46,9 +46,9 @@
#define TIMEOUT_VERSION TIMEOUT_V_REL
#define TIMEOUT_VENDOR "william@25thandClement.com"
#define TIMEOUT_V_REL 0x20140103
#define TIMEOUT_V_ABI 0x20140103
#define TIMEOUT_V_API 0x20140103
#define TIMEOUT_V_REL 0x20160224
#define TIMEOUT_V_ABI 0x20160224
#define TIMEOUT_V_API 0x20160224
TIMEOUT_PUBLIC int timeout_version(void);
......@@ -115,27 +115,29 @@ 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 */
#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 */
TAILQ_ENTRY(timeout) tqe;
/* entry member for struct timeout_list lists */
#ifndef TIMEOUT_DISABLE_CALLBACKS
struct timeout_cb callback;
/* optional callback information */
#endif
#ifndef TIMEOUT_DISABLE_INTERVALS
timeout_t interval;
/* timeout interval if periodic */
#endif
#ifndef TIMEOUT_DISABLE_RELATIVE_ACCESS
struct timeouts *timeouts;
/* timeouts collection if member of */
#endif
}; /* struct timeout */
......@@ -200,29 +202,29 @@ TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *, FILE *);
#define TIMEOUTS_EXPIRED 0x20
#define TIMEOUTS_ALL (TIMEOUTS_PENDING|TIMEOUTS_EXPIRED)
#define TIMEOUTS_CURSOR_INITIALIZER(flags) { (flags) }
#define TIMEOUTS_IT_INITIALIZER(flags) { (flags) }
#define TIMEOUTS_CURSOR_INIT(cur, _flags) do { \
#define TIMEOUTS_IT_INIT(cur, _flags) do { \
(cur)->flags = (_flags); \
(cur)->pc = 0; \
} while (0)
struct timeouts_cursor {
struct timeouts_it {
int flags;
unsigned pc, i, j;
struct timeout *to;
}; /* struct timeouts_cursor */
}; /* struct timeouts_it */
TIMEOUT_PUBLIC struct timeout *timeouts_next(struct timeouts *, struct timeouts_cursor *);
TIMEOUT_PUBLIC struct timeout *timeouts_next(struct timeouts *, struct timeouts_it *);
/* return next timeout in pending wheel or expired queue. caller can delete
* the returned timeout, but should not otherwise manipulate the timing
* wheel. in particular, caller SHOULD NOT delete any other timeout as that
* could invalidate cursor state and trigger a use-after-free.
*/
#define TIMEOUTS_FOREACH(var, T, flags) \
struct timeouts_cursor _foreach_cursor = TIMEOUTS_CURSOR_INITIALIZER((flags)); \
while (((var) = timeouts_next((T), &_foreach_cursor)))
#define TIMEOUTS_FOREACH(var, T, flags) \
struct timeouts_it _it = TIMEOUTS_IT_INITIALIZER((flags)); \
while (((var) = timeouts_next((T), &_it)))
/*
......
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