diff --git a/bin/tests/task_test.c b/bin/tests/task_test.c index 3a2d92b00f..12d405cf51 100644 --- a/bin/tests/task_test.c +++ b/bin/tests/task_test.c @@ -22,7 +22,7 @@ my_callback(task_t task, task_event_t event) j = 0; for (i = 0; i < 1000000; i++) j += 100; - printf("task %s: %d\n", name, j); + printf("task %s (%p): %d\n", name, task, j); return (ISC_FALSE); } @@ -31,7 +31,7 @@ static isc_boolean_t my_shutdown(task_t task, task_event_t event) { char *name = event->arg; - printf("shutdown %s\n", name); + printf("shutdown %s (%p)\n", name, task); return (ISC_TRUE); } @@ -51,8 +51,8 @@ main(int argc, char *argv[]) { task_t t3 = NULL, t4 = NULL; task_event_t event; unsigned int workers; - timer_manager_t timgr; - timer_t ti1, ti2; + isc_timermgr_t timgr; + isc_timer_t ti1, ti2; os_time_t absolute, interval; if (argc > 1) @@ -71,17 +71,19 @@ main(int argc, char *argv[]) { INSIST(task_create(manager, my_shutdown, "4", 0, &t4)); timgr = NULL; - INSIST(timer_manager_create(mctx, &timgr) == ISC_R_SUCCESS); + INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS); ti1 = NULL; absolute.seconds = 0; absolute.nanoseconds = 0; interval.seconds = 1; interval.nanoseconds = 0; - INSIST(timer_create(timgr, timer_type_ticker, absolute, interval, - t1, my_tick, "foo", &ti1) == ISC_R_SUCCESS); + INSIST(isc_timer_create(timgr, isc_timertype_ticker, + absolute, interval, + t1, my_tick, "foo", &ti1) == ISC_R_SUCCESS); ti2 = NULL; - INSIST(timer_create(timgr, timer_type_ticker, absolute, interval, - t2, my_tick, "bar", &ti2) == ISC_R_SUCCESS); + INSIST(isc_timer_create(timgr, isc_timertype_ticker, + absolute, interval, + t2, my_tick, "bar", &ti2) == ISC_R_SUCCESS); printf("task 1 = %p\n", t1); printf("task 2 = %p\n", t2); @@ -141,9 +143,9 @@ main(int argc, char *argv[]) { sleep(10); printf("destroy\n"); - timer_detach(&ti1); - timer_detach(&ti2); - timer_manager_destroy(&timgr); + isc_timer_detach(&ti1); + isc_timer_detach(&ti2); + isc_timermgr_destroy(&timgr); task_manager_destroy(&manager); printf("destroyed\n"); diff --git a/bin/tests/timer_test.c b/bin/tests/timer_test.c index f9524082c9..cc72910353 100644 --- a/bin/tests/timer_test.c +++ b/bin/tests/timer_test.c @@ -13,14 +13,14 @@ mem_context_t mctx = NULL; task_t t1, t2, t3; -timer_t ti1, ti2, ti3; +isc_timer_t ti1, ti2, ti3; int tick_count = 0; static isc_boolean_t shutdown_task(task_t task, task_event_t event) { char *name = event->arg; - printf("shutdown %s\n", name); + printf("task %p shutdown %s\n", task, name); return (ISC_TRUE); } @@ -29,13 +29,13 @@ tick(task_t task, task_event_t event) { char *name = event->arg; - INSIST(event->type == TIMER_EVENT_TICK); + INSIST(event->type == ISC_TIMEREVENT_TICK); printf("task %s (%p) tick\n", name, task); tick_count++; if (tick_count % 3 == 0) - timer_touch(ti3); + isc_timer_touch(ti3); if (tick_count == 7) { os_time_t expires, interval, now; @@ -47,8 +47,8 @@ tick(task_t task, task_event_t event) interval.seconds = 4; interval.nanoseconds = 0; printf("*** resetting ti3 ***\n"); - INSIST(timer_reset(ti3, timer_type_once, expires, interval, - ISC_TRUE) + INSIST(isc_timer_reset(ti3, isc_timertype_once, expires, + interval, ISC_TRUE) == ISC_R_SUCCESS); } @@ -61,10 +61,10 @@ timeout(task_t task, task_event_t event) char *name = event->arg; char *type; - INSIST(event->type == TIMER_EVENT_IDLE || - event->type == TIMER_EVENT_LIFE); + INSIST(event->type == ISC_TIMEREVENT_IDLE || + event->type == ISC_TIMEREVENT_LIFE); - if (event->type == TIMER_EVENT_IDLE) + if (event->type == ISC_TIMEREVENT_IDLE) type = "idle"; else type = "life"; @@ -80,7 +80,7 @@ timeout(task_t task, task_event_t event) void main(int argc, char *argv[]) { task_manager_t manager = NULL; - timer_manager_t timgr = NULL; + isc_timermgr_t timgr = NULL; unsigned int workers; os_time_t expires, interval, now; @@ -95,7 +95,7 @@ main(int argc, char *argv[]) { INSIST(task_create(manager, shutdown_task, "1", 0, &t1)); INSIST(task_create(manager, shutdown_task, "2", 0, &t2)); INSIST(task_create(manager, shutdown_task, "3", 0, &t3)); - INSIST(timer_manager_create(mctx, &timgr) == ISC_R_SUCCESS); + INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS); printf("task 1: %p\n", t1); printf("task 2: %p\n", t2); @@ -107,21 +107,21 @@ main(int argc, char *argv[]) { expires.nanoseconds = 0; interval.seconds = 2; interval.nanoseconds = 0; - INSIST(timer_create(timgr, timer_type_once, expires, interval, - t2, timeout, "2", &ti2) == ISC_R_SUCCESS); + INSIST(isc_timer_create(timgr, isc_timertype_once, expires, interval, + t2, timeout, "2", &ti2) == ISC_R_SUCCESS); expires.seconds = 0; expires.nanoseconds = 0; interval.seconds = 1; interval.nanoseconds = 0; - INSIST(timer_create(timgr, timer_type_ticker, expires, interval, - t1, tick, "1", &ti1) == ISC_R_SUCCESS); + INSIST(isc_timer_create(timgr, isc_timertype_ticker, expires, interval, + t1, tick, "1", &ti1) == ISC_R_SUCCESS); expires.seconds = 10; expires.nanoseconds = 0; os_time_add(&now, &expires, &expires); interval.seconds = 2; interval.nanoseconds = 0; - INSIST(timer_create(timgr, timer_type_once, expires, interval, - t3, timeout, "3", &ti3) == ISC_R_SUCCESS); + INSIST(isc_timer_create(timgr, isc_timertype_once, expires, interval, + t3, timeout, "3", &ti3) == ISC_R_SUCCESS); task_detach(&t1); task_detach(&t2); @@ -129,11 +129,11 @@ main(int argc, char *argv[]) { sleep(15); printf("destroy\n"); - timer_detach(&ti1); - timer_detach(&ti2); - timer_detach(&ti3); + isc_timer_detach(&ti1); + isc_timer_detach(&ti2); + isc_timer_detach(&ti3); sleep(2); - timer_manager_destroy(&timgr); + isc_timermgr_destroy(&timgr); task_manager_destroy(&manager); printf("destroyed\n"); diff --git a/lib/isc/include/isc/event.h b/lib/isc/include/isc/event.h index 68476b03c9..80f12138d5 100644 --- a/lib/isc/include/isc/event.h +++ b/lib/isc/include/isc/event.h @@ -10,17 +10,16 @@ * An event class is a 16 bit number, the most sigificant bit of which must be * zero. Each class may contain up to 65536 events. An event type is * formed by adding the event number within the class to the class number. - * E.g., the first event in the timer class is EVENT_CLASS_TIMER + 1. Event - * number zero is always reserved in each class. + * E.g., the first event in the timer class is ISC_EVENTCLASS_TIMER + 1. + * Event number zero is always reserved in each class. */ -#define EVENT_CLASS(class) ((class) << 16) +#define ISC_EVENTCLASS(class) ((class) << 16) -#define EVENT_CLASS_TASK EVENT_CLASS(0) - -#define EVENT_CLASS_TIMER EVENT_CLASS(1) -#define EVENT_CLASS_SOCKET EVENT_CLASS(2) -#define EVENT_CLASS_FILE EVENT_CLASS(3) +#define ISC_EVENTCLASS_TASK ISC_EVENTCLASS(0) +#define ISC_EVENTCLASS_TIMER ISC_EVENTCLASS(1) +#define ISC_EVENTCLASS_SOCKET ISC_EVENTCLASS(2) +#define ISC_EVENTCLASS_FILE ISC_EVENTCLASS(3) /* * Event classes >= 1024 and <= 32767 are reserved for application use. diff --git a/lib/isc/include/isc/result.h b/lib/isc/include/isc/result.h index 44a2d507c0..989edc152f 100644 --- a/lib/isc/include/isc/result.h +++ b/lib/isc/include/isc/result.h @@ -2,7 +2,10 @@ #ifndef ISC_RESULT_H #define ISC_RESULT_H 1 -typedef unsigned int isc_result; +/* XXX HACK XXX */ +#define isc_result isc_result_t + +typedef unsigned int isc_result_t; #define ISC_R_SUCCESS 0 #define ISC_R_NOMEMORY 1 diff --git a/lib/isc/include/isc/timer.h b/lib/isc/include/isc/timer.h index 3b206dccaf..709129bbb3 100644 --- a/lib/isc/include/isc/timer.h +++ b/lib/isc/include/isc/timer.h @@ -32,7 +32,7 @@ * making a call that affects that timer. Failure to follow this rule * can result in deadlock. * - * The caller must ensure that timer_manager_destroy() is called only + * The caller must ensure that isc_timermgr_destroy() is called only * once for a given manager. * * Reliability: @@ -64,39 +64,39 @@ *** Types ***/ -typedef struct timer_t *timer_t; -typedef struct timer_manager_t *timer_manager_t; +typedef struct isc_timer *isc_timer_t; +typedef struct isc_timermgr *isc_timermgr_t; typedef enum { - timer_type_ticker = 0, timer_type_once -} timer_type_t; + isc_timertype_ticker = 0, isc_timertype_once +} isc_timertype_t; -typedef struct timer_event { +typedef struct isc_timerevent { struct task_event common; /* XXX Anything else? XXX */ -} *timer_event_t; +} *isc_timerevent_t; -#define TIMER_EVENT_TICK (EVENT_CLASS_TIMER + 1) -#define TIMER_EVENT_IDLE (EVENT_CLASS_TIMER + 2) -#define TIMER_EVENT_LIFE (EVENT_CLASS_TIMER + 3) +#define ISC_TIMEREVENT_TICK (ISC_EVENTCLASS_TIMER + 1) +#define ISC_TIMEREVENT_IDLE (ISC_EVENTCLASS_TIMER + 2) +#define ISC_TIMEREVENT_LIFE (ISC_EVENTCLASS_TIMER + 3) /*** *** Timer and Timer Manager Functions *** *** Note: all Ensures conditions apply only if the result is success for - *** those functions which return an isc_result. + *** those functions which return an isc_result_t. ***/ -isc_result -timer_create(timer_manager_t manager, - timer_type_t type, - os_time_t expires, - os_time_t interval, - task_t task, - task_action_t action, - void *arg, - timer_t *timerp); +isc_result_t +isc_timer_create(isc_timermgr_t manager, + isc_timertype_t type, + os_time_t expires, + os_time_t interval, + task_t task, + task_action_t action, + void *arg, + isc_timer_t *timerp); /* * Create a new 'type' timer managed by 'manager'. The timers parameters * are specified by 'expires' and 'interval'. Events will be posted to @@ -143,12 +143,12 @@ timer_create(timer_manager_t manager, * Unexpected error */ -isc_result -timer_reset(timer_t timer, - timer_type_t type, - os_time_t expires, - os_time_t interval, - isc_boolean_t purge); +isc_result_t +isc_timer_reset(isc_timer_t timer, + isc_timertype_t type, + os_time_t expires, + os_time_t interval, + isc_boolean_t purge); /* * Change the timer's type, expires, and interval values to the given * values. If 'purge' is TRUE, any pending events from this timer @@ -158,7 +158,7 @@ timer_reset(timer_t timer, * * 'timer' is a valid timer * - * The same requirements that timer_create() imposes on 'type', + * The same requirements that isc_timer_create() imposes on 'type', * 'expires' and 'interval' apply. * * Ensures: @@ -174,8 +174,8 @@ timer_reset(timer_t timer, * Unexpected error */ -isc_result -timer_touch(timer_t timer); +isc_result_t +isc_timer_touch(isc_timer_t timer); /* * Set the last-touched time of 'timer' to the current time. * @@ -196,7 +196,7 @@ timer_touch(timer_t timer); */ void -timer_attach(timer_t timer, timer_t *timerp); +isc_timer_attach(isc_timer_t timer, isc_timer_t *timerp); /* * Attach *timerp to timer. * @@ -212,7 +212,7 @@ timer_attach(timer_t timer, timer_t *timerp); */ void -timer_detach(timer_t *timerp); +isc_timer_detach(isc_timer_t *timerp); /* * Detach *timerp from its timer. * @@ -234,8 +234,8 @@ timer_detach(timer_t *timerp); * All resources used by the timer have been freed */ -isc_result -timer_manager_create(mem_context_t mctx, timer_manager_t *managerp); +isc_result_t +isc_timermgr_create(mem_context_t mctx, isc_timermgr_t *managerp); /* * Create a timer manager. * @@ -247,11 +247,11 @@ timer_manager_create(mem_context_t mctx, timer_manager_t *managerp); * * 'mctx' is a valid memory context. * - * 'managerp' points to a NULL timer_manager_t. + * 'managerp' points to a NULL isc_timermgr_t. * * Ensures: * - * '*managerp' is a valid timer_manager_t. + * '*managerp' is a valid isc_timermgr_t. * * Returns: * @@ -261,7 +261,7 @@ timer_manager_create(mem_context_t mctx, timer_manager_t *managerp); */ void -timer_manager_destroy(timer_manager_t *); +isc_timermgr_destroy(isc_timermgr_t *); /* * Destroy a timer manager. * @@ -269,12 +269,12 @@ timer_manager_destroy(timer_manager_t *); * * This routine blocks until there are no timers left in the manager, * so if the caller holds any timer references using the manager, it - * must detach them before calling timer_manager_destroy() or it will + * must detach them before calling isc_timermgr_destroy() or it will * block forever. * * Requires: * - * '*managerp' is a valid timer_manager_t. + * '*managerp' is a valid isc_timermgr_t. * * Ensures: * diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 99bda5cb25..9fd5e9952a 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -27,7 +27,7 @@ #define ZERO(t) ((t).seconds == 0 && \ (t).nanoseconds == 0) -#ifdef TIMER_TRACE +#ifdef ISC_TIMER_TRACE #define XTRACE(s) printf("%s\n", (s)) #define XTRACEID(s, t) printf("%s %p\n", (s), (t)) #define XTRACETIME(s, d) printf("%s %lu.%09lu\n", (s), \ @@ -39,21 +39,21 @@ #define XTRACEID(s, t) #define XTRACETIME(s, d) #define XTRACETIMER(s, t, d) -#endif /* TIMER_TRACE */ +#endif /* ISC_TIMER_TRACE */ #define TIMER_MAGIC 0x54494D52U /* TIMR. */ #define VALID_TIMER(t) ((t) != NULL && \ (t)->magic == TIMER_MAGIC) -struct timer_t { +struct isc_timer { /* Not locked. */ unsigned int magic; - timer_manager_t manager; + isc_timermgr_t manager; os_mutex_t lock; /* Locked by timer lock. */ unsigned int references; os_time_t idle; /* Locked by manager lock. */ - timer_type_t type; + isc_timertype_t type; os_time_t expires; os_time_t interval; task_t task; @@ -61,21 +61,21 @@ struct timer_t { void * arg; unsigned int index; os_time_t due; - LINK(struct timer_t) link; + LINK(struct isc_timer) link; }; #define TIMER_MANAGER_MAGIC 0x54494D4DU /* TIMM. */ #define VALID_MANAGER(m) ((m) != NULL && \ (m)->magic == TIMER_MANAGER_MAGIC) -struct timer_manager_t { +struct isc_timermgr { /* Not locked. */ unsigned int magic; mem_context_t mctx; os_mutex_t lock; /* Locked by manager lock. */ isc_boolean_t done; - LIST(struct timer_t) timers; + LIST(struct isc_timer) timers; unsigned int nscheduled; os_time_t due; os_condition_t wakeup; @@ -84,9 +84,9 @@ struct timer_manager_t { }; static inline isc_result -schedule(timer_t timer, os_time_t *nowp, isc_boolean_t broadcast_ok) { +schedule(isc_timer_t timer, os_time_t *nowp, isc_boolean_t broadcast_ok) { isc_result result; - timer_manager_t manager; + isc_timermgr_t manager; os_time_t due; int cmp; @@ -97,7 +97,7 @@ schedule(timer_t timer, os_time_t *nowp, isc_boolean_t broadcast_ok) { /* * Compute the new due time. */ - if (timer->type == timer_type_ticker) + if (timer->type == isc_timertype_ticker) os_time_add(nowp, &timer->interval, &due); else { if (ZERO(timer->idle)) @@ -158,9 +158,9 @@ schedule(timer_t timer, os_time_t *nowp, isc_boolean_t broadcast_ok) { } static inline void -deschedule(timer_t timer) { +deschedule(isc_timer_t timer) { isc_boolean_t need_wakeup = ISC_FALSE; - timer_manager_t manager; + isc_timermgr_t manager; /* * The caller must ensure locking. @@ -182,8 +182,8 @@ deschedule(timer_t timer) { } static void -destroy(timer_t timer) { - timer_manager_t manager = timer->manager; +destroy(isc_timer_t timer) { + isc_timermgr_t manager = timer->manager; /* * The caller must ensure locking. @@ -204,11 +204,12 @@ destroy(timer_t timer) { } isc_result -timer_create(timer_manager_t manager, timer_type_t type, - os_time_t expires, os_time_t interval, - task_t task, task_action_t action, void *arg, timer_t *timerp) +isc_timer_create(isc_timermgr_t manager, isc_timertype_t type, + os_time_t expires, os_time_t interval, + task_t task, task_action_t action, void *arg, + isc_timer_t *timerp) { - timer_t timer; + isc_timer_t timer; isc_result result; os_time_t now; @@ -244,7 +245,7 @@ timer_create(timer_manager_t manager, timer_type_t type, timer->magic = TIMER_MAGIC; timer->manager = manager; timer->references = 1; - if (type == timer_type_once && !ZERO(interval)) + if (type == isc_timertype_once && !ZERO(interval)) os_time_add(&now, &interval, &timer->idle); else { timer->idle.seconds = 0; @@ -283,11 +284,11 @@ timer_create(timer_manager_t manager, timer_type_t type, } isc_result -timer_reset(timer_t timer, timer_type_t type, - os_time_t expires, os_time_t interval, isc_boolean_t purge) +isc_timer_reset(isc_timer_t timer, isc_timertype_t type, + os_time_t expires, os_time_t interval, isc_boolean_t purge) { os_time_t now; - timer_manager_t manager; + isc_timermgr_t manager; isc_result result; /* @@ -322,7 +323,7 @@ timer_reset(timer_t timer, timer_type_t type, timer->type = type; timer->expires = expires; timer->interval = interval; - if (type == timer_type_once && !ZERO(interval)) + if (type == isc_timertype_once && !ZERO(interval)) os_time_add(&now, &interval, &timer->idle); else { timer->idle.seconds = 0; @@ -337,7 +338,7 @@ timer_reset(timer_t timer, timer_type_t type, } isc_result -timer_touch(timer_t timer) { +isc_timer_touch(isc_timer_t timer) { isc_result result; os_time_t now; @@ -349,7 +350,7 @@ timer_touch(timer_t timer) { LOCK(&timer->lock); - INSIST(timer->type == timer_type_once); + INSIST(timer->type == isc_timertype_once); result = os_time_get(&now); if (result != ISC_R_SUCCESS) { @@ -366,7 +367,7 @@ timer_touch(timer_t timer) { } void -timer_attach(timer_t timer, timer_t *timerp) { +isc_timer_attach(isc_timer_t timer, isc_timer_t *timerp) { /* * Attach *timerp to timer. */ @@ -382,8 +383,8 @@ timer_attach(timer_t timer, timer_t *timerp) { } void -timer_detach(timer_t *timerp) { - timer_t timer; +isc_timer_detach(isc_timer_t *timerp) { + isc_timer_t timer; isc_boolean_t free_timer = ISC_FALSE; /* @@ -408,30 +409,30 @@ timer_detach(timer_t *timerp) { } static void -dispatch(timer_manager_t manager, os_time_t *nowp) { +dispatch(isc_timermgr_t manager, os_time_t *nowp) { isc_boolean_t done = ISC_FALSE, post_event, need_schedule; task_event_t event; task_eventtype_t type = 0; - timer_t timer; + isc_timer_t timer; isc_result result; while (manager->nscheduled > 0 && !done) { timer = isc_heap_element(manager->heap, 1); if (os_time_compare(nowp, &timer->due) >= 0) { - if (timer->type == timer_type_ticker) { - type = TIMER_EVENT_TICK; + if (timer->type == isc_timertype_ticker) { + type = ISC_TIMEREVENT_TICK; post_event = ISC_TRUE; need_schedule = ISC_TRUE; } else if (!ZERO(timer->expires) && os_time_compare(nowp, &timer->expires) >= 0) { - type = TIMER_EVENT_LIFE; + type = ISC_TIMEREVENT_LIFE; post_event = ISC_TRUE; need_schedule = ISC_FALSE; } else if (!ZERO(timer->idle) && os_time_compare(nowp, &timer->idle) >= 0) { - type = TIMER_EVENT_IDLE; + type = ISC_TIMEREVENT_IDLE; post_event = ISC_TRUE; need_schedule = ISC_FALSE; } else { @@ -480,7 +481,7 @@ dispatch(timer_manager_t manager, os_time_t *nowp) { static void * run(void *uap) { - timer_manager_t manager = uap; + isc_timermgr_t manager = uap; isc_boolean_t timeout; os_time_t now; @@ -509,7 +510,7 @@ run(void *uap) { static isc_boolean_t sooner(void *v1, void *v2) { - timer_t t1, t2; + isc_timer_t t1, t2; t1 = v1; t2 = v2; @@ -523,7 +524,7 @@ sooner(void *v1, void *v2) { static void set_index(void *what, unsigned int index) { - timer_t timer; + isc_timer_t timer; timer = what; REQUIRE(VALID_TIMER(timer)); @@ -532,8 +533,8 @@ set_index(void *what, unsigned int index) { } isc_result -timer_manager_create(mem_context_t mctx, timer_manager_t *managerp) { - timer_manager_t manager; +isc_timermgr_create(mem_context_t mctx, isc_timermgr_t *managerp) { + isc_timermgr_t manager; isc_result result; /* @@ -590,8 +591,8 @@ timer_manager_create(mem_context_t mctx, timer_manager_t *managerp) { } void -timer_manager_destroy(timer_manager_t *managerp) { - timer_manager_t manager; +isc_timermgr_destroy(isc_timermgr_t *managerp) { + isc_timermgr_t manager; /* * Destroy a timer manager.