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