Commit 410b2d88 authored by william's avatar william

add version routines and TIMEOUT_PUBLIC prefix to exported routines so...

add version routines and TIMEOUT_PUBLIC prefix to exported routines so applications can optionally compile completely statically (by defining TIMEOUT_PUBLIC to `static'
parent 586ca7fb
...@@ -221,7 +221,7 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) { ...@@ -221,7 +221,7 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) {
} /* timeouts_init() */ } /* timeouts_init() */
void timeouts_del(struct timeouts *T, struct timeout *to) { TIMEOUT_PUBLIC void timeouts_del(struct timeouts *T, struct timeout *to) {
if (to->pending) { if (to->pending) {
if (to->pending != &T->expired && TAILQ_EMPTY(to->pending)) { if (to->pending != &T->expired && TAILQ_EMPTY(to->pending)) {
ptrdiff_t index = to->pending - &T->wheel[0][0]; ptrdiff_t index = to->pending - &T->wheel[0][0];
...@@ -302,7 +302,7 @@ static void timeouts_readd(struct timeouts *T, struct timeout *to) { ...@@ -302,7 +302,7 @@ static void timeouts_readd(struct timeouts *T, struct timeout *to) {
} /* timeouts_readd() */ } /* timeouts_readd() */
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) {
if (to->flags & TIMEOUT_INT) if (to->flags & TIMEOUT_INT)
to->interval = MAX(1, timeout); to->interval = MAX(1, timeout);
...@@ -313,12 +313,12 @@ void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t timeout) { ...@@ -313,12 +313,12 @@ void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t timeout) {
} /* timeouts_add() */ } /* timeouts_add() */
void timeouts_addf(struct timeouts *T, struct timeout *to, double timeout) { TIMEOUT_PUBLIC void timeouts_addf(struct timeouts *T, struct timeout *to, double timeout) {
timeouts_add(T, to, timeout * T->hertz); timeouts_add(T, to, timeout * T->hertz);
} /* timeouts_addf() */ } /* timeouts_addf() */
void timeouts_update(struct timeouts *T, abstime_t curtime) { TIMEOUT_PUBLIC void timeouts_update(struct timeouts *T, abstime_t curtime) {
timeout_t elapsed = curtime - T->curtime; timeout_t elapsed = curtime - T->curtime;
struct timeout_list todo; struct timeout_list todo;
int wheel; int wheel;
...@@ -383,12 +383,12 @@ void timeouts_update(struct timeouts *T, abstime_t curtime) { ...@@ -383,12 +383,12 @@ void timeouts_update(struct timeouts *T, abstime_t curtime) {
} /* timeouts_update() */ } /* timeouts_update() */
void timeouts_step(struct timeouts *T, reltime_t elapsed) { TIMEOUT_PUBLIC void timeouts_step(struct timeouts *T, reltime_t elapsed) {
timeouts_update(T, T->curtime + elapsed); timeouts_update(T, T->curtime + elapsed);
} /* timeouts_step() */ } /* timeouts_step() */
bool timeouts_pending(struct timeouts *T) { TIMEOUT_PUBLIC bool timeouts_pending(struct timeouts *T) {
wheel_t pending = 0; wheel_t pending = 0;
int wheel; int wheel;
...@@ -400,7 +400,7 @@ bool timeouts_pending(struct timeouts *T) { ...@@ -400,7 +400,7 @@ bool timeouts_pending(struct timeouts *T) {
} /* timeouts_pending() */ } /* timeouts_pending() */
bool timeouts_expired(struct timeouts *T) { TIMEOUT_PUBLIC bool timeouts_expired(struct timeouts *T) {
return !TAILQ_EMPTY(&T->expired); return !TAILQ_EMPTY(&T->expired);
} /* timeouts_expired() */ } /* timeouts_expired() */
...@@ -453,7 +453,7 @@ static timeout_t timeouts_int(struct timeouts *T) { ...@@ -453,7 +453,7 @@ static timeout_t timeouts_int(struct timeouts *T) {
* Calculate the interval our caller can wait before needing to process * Calculate the interval our caller can wait before needing to process
* events. * events.
*/ */
timeout_t timeouts_timeout(struct timeouts *T) { TIMEOUT_PUBLIC timeout_t timeouts_timeout(struct timeouts *T) {
if (!TAILQ_EMPTY(&T->expired)) if (!TAILQ_EMPTY(&T->expired))
return 0; return 0;
...@@ -461,7 +461,7 @@ timeout_t timeouts_timeout(struct timeouts *T) { ...@@ -461,7 +461,7 @@ timeout_t timeouts_timeout(struct timeouts *T) {
} /* timeouts_timeout() */ } /* timeouts_timeout() */
struct timeout *timeouts_get(struct timeouts *T) { TIMEOUT_PUBLIC struct timeout *timeouts_get(struct timeouts *T) {
if (!TAILQ_EMPTY(&T->expired)) { if (!TAILQ_EMPTY(&T->expired)) {
struct timeout *to = TAILQ_FIRST(&T->expired); struct timeout *to = TAILQ_FIRST(&T->expired);
...@@ -518,7 +518,7 @@ static struct timeout *timeouts_min(struct timeouts *T) { ...@@ -518,7 +518,7 @@ static struct timeout *timeouts_min(struct timeouts *T) {
} \ } \
} while (0) } while (0)
bool timeouts_check(struct timeouts *T, FILE *fp) { TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *T, FILE *fp) {
timeout_t timeout; timeout_t timeout;
struct timeout *to; struct timeout *to;
...@@ -548,7 +548,7 @@ bool timeouts_check(struct timeouts *T, FILE *fp) { ...@@ -548,7 +548,7 @@ bool timeouts_check(struct timeouts *T, FILE *fp) {
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct timeout *timeout_init(struct timeout *to, int flags) { TIMEOUT_PUBLIC struct timeout *timeout_init(struct timeout *to, int flags) {
memset(to, 0, sizeof *to); memset(to, 0, sizeof *to);
to->flags = flags; to->flags = flags;
...@@ -557,21 +557,51 @@ struct timeout *timeout_init(struct timeout *to, int flags) { ...@@ -557,21 +557,51 @@ struct timeout *timeout_init(struct timeout *to, int flags) {
} /* timeout_init() */ } /* timeout_init() */
bool timeout_pending(struct timeout *to) { TIMEOUT_PUBLIC bool timeout_pending(struct timeout *to) {
return to->pending && to->pending != &to->timeouts->expired; return to->pending && to->pending != &to->timeouts->expired;
} /* timeout_pending() */ } /* timeout_pending() */
bool timeout_expired(struct timeout *to) { TIMEOUT_PUBLIC bool timeout_expired(struct timeout *to) {
return to->pending && to->pending == &to->timeouts->expired; return to->pending && to->pending == &to->timeouts->expired;
} /* timeout_expired() */ } /* timeout_expired() */
void timeout_del(struct timeout *to) { TIMEOUT_PUBLIC void timeout_del(struct timeout *to) {
timeouts_del(to->timeouts, to); timeouts_del(to->timeouts, to);
} /* timeout_del() */ } /* timeout_del() */
/*
* V E R S I O N I N T E R F A C E S
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
TIMEOUT_PUBLIC int timeout_version(void) {
return TIMEOUT_VERSION;
} /* timeout_version() */
TIMEOUT_PUBLIC const char *timeout_vendor(void) {
return TIMEOUT_VENDOR;
} /* timeout_version() */
TIMEOUT_PUBLIC int timeout_v_rel(void) {
return TIMEOUT_V_REL;
} /* timeout_version() */
TIMEOUT_PUBLIC int timeout_v_abi(void) {
return TIMEOUT_V_ABI;
} /* timeout_version() */
TIMEOUT_PUBLIC int timeout_v_api(void) {
return TIMEOUT_V_API;
} /* timeout_version() */
#if TIMEOUT_MAIN - 0 #if TIMEOUT_MAIN - 0
#include <stdio.h> #include <stdio.h>
......
...@@ -34,6 +34,33 @@ ...@@ -34,6 +34,33 @@
#include <sys/queue.h> /* TAILQ(3) */ #include <sys/queue.h> /* TAILQ(3) */
/*
* V E R S I O N I N T E R F A C E S
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#if !defined TIMEOUT_PUBLIC
#define TIMEOUT_PUBLIC
#endif
#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
TIMEOUT_PUBLIC int timeout_version(void);
TIMEOUT_PUBLIC const char *timeout_vendor(void);
TIMEOUT_PUBLIC int timeout_v_rel(void);
TIMEOUT_PUBLIC int timeout_v_abi(void);
TIMEOUT_PUBLIC int timeout_v_api(void);
/* /*
* I N T E G E R T Y P E I N T E R F A C E S * I N T E G E R T Y P E I N T E R F A C E S
* *
...@@ -99,16 +126,16 @@ struct timeout { ...@@ -99,16 +126,16 @@ struct timeout {
}; /* struct timeout */ }; /* struct timeout */
struct timeout *timeout_init(struct timeout *, int); TIMEOUT_PUBLIC struct timeout *timeout_init(struct timeout *, int);
/* initialize timeout structure (same as TIMEOUT_INITIALIZER) */ /* initialize timeout structure (same as TIMEOUT_INITIALIZER) */
bool timeout_pending(struct timeout *); TIMEOUT_PUBLIC bool timeout_pending(struct timeout *);
/* true if on timing wheel, false otherwise */ /* true if on timing wheel, false otherwise */
bool timeout_expired(struct timeout *); TIMEOUT_PUBLIC bool timeout_expired(struct timeout *);
/* true if on expired queue, false otherwise */ /* true if on expired queue, false otherwise */
void timeout_del(struct timeout *); TIMEOUT_PUBLIC void timeout_del(struct timeout *);
/* remove timeout from any timing wheel (okay if not member of any) */ /* remove timeout from any timing wheel (okay if not member of any) */
...@@ -119,37 +146,37 @@ void timeout_del(struct timeout *); ...@@ -119,37 +146,37 @@ void timeout_del(struct timeout *);
struct timeouts; struct timeouts;
struct timeouts *timeouts_open(timeout_t); TIMEOUT_PUBLIC struct timeouts *timeouts_open(timeout_t);
/* open a new timing wheel, setting optional HZ */ /* open a new timing wheel, setting optional HZ (for float conversions) */
void timeouts_close(struct timeouts *); TIMEOUT_PUBLIC void timeouts_close(struct timeouts *);
/* destroy timing wheel */ /* destroy timing wheel */
void timeouts_update(struct timeouts *, timeout_t); TIMEOUT_PUBLIC void timeouts_update(struct timeouts *, timeout_t);
/* update timing wheel with current absolute time */ /* update timing wheel with current absolute time */
void timeouts_step(struct timeouts *, timeout_t); TIMEOUT_PUBLIC void timeouts_step(struct timeouts *, timeout_t);
/* step timing wheel by relative time */ /* step timing wheel by relative time */
timeout_t timeouts_timeout(struct timeouts *); TIMEOUT_PUBLIC timeout_t timeouts_timeout(struct timeouts *);
/* return interval to next required update */ /* return interval to next required update */
void timeouts_add(struct timeouts *, struct timeout *, timeout_t); TIMEOUT_PUBLIC void timeouts_add(struct timeouts *, struct timeout *, timeout_t);
/* add timeout to timing wheel */ /* add timeout to timing wheel */
void timeouts_addf(struct timeouts *, struct timeout *, double); TIMEOUT_PUBLIC void timeouts_addf(struct timeouts *, struct timeout *, double);
/* add timeout to timing wheel, translating floating point timeout */ /* add timeout to timing wheel, translating floating point timeout */
void timeouts_del(struct timeouts *, struct timeout *); TIMEOUT_PUBLIC void timeouts_del(struct timeouts *, struct timeout *);
/* remove timeout from any timing wheel or expired queue (okay if on neither) */ /* remove timeout from any timing wheel or expired queue (okay if on neither) */
bool timeouts_pending(struct timeouts *); TIMEOUT_PUBLIC bool timeouts_pending(struct timeouts *);
/* return true if any timeouts pending on timing wheel */ /* return true if any timeouts pending on timing wheel */
bool timeouts_expired(struct timeouts *); TIMEOUT_PUBLIC bool timeouts_expired(struct timeouts *);
/* return true if any timeouts on expired queue */ /* return true if any timeouts on expired queue */
bool timeouts_check(struct timeouts *, FILE *); TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *, FILE *);
/* return true if invariants hold. describes failures to optional file handle. */ /* return true if invariants hold. describes failures to optional file handle. */
......
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