Commit c92ba071 authored by Bob Halley's avatar Bob Halley

more renaming

parent 5f74ac33
......@@ -14,7 +14,7 @@
mem_context_t mctx = NULL;
static isc_boolean_t
my_callback(task_t task, task_event_t event)
my_callback(isc_task_t task, isc_event_t event)
{
int i, j;
char *name = event->arg;
......@@ -28,7 +28,7 @@ my_callback(task_t task, task_event_t event)
}
static isc_boolean_t
my_shutdown(task_t task, task_event_t event) {
my_shutdown(isc_task_t task, isc_event_t event) {
char *name = event->arg;
printf("shutdown %s (%p)\n", name, task);
......@@ -36,7 +36,7 @@ my_shutdown(task_t task, task_event_t event) {
}
static isc_boolean_t
my_tick(task_t task, task_event_t event)
my_tick(isc_task_t task, isc_event_t event)
{
char *name = event->arg;
......@@ -46,10 +46,10 @@ my_tick(task_t task, task_event_t event)
void
main(int argc, char *argv[]) {
task_manager_t manager = NULL;
task_t t1 = NULL, t2 = NULL;
task_t t3 = NULL, t4 = NULL;
task_event_t event;
isc_taskmgr_t manager = NULL;
isc_task_t t1 = NULL, t2 = NULL;
isc_task_t t3 = NULL, t4 = NULL;
isc_event_t event;
unsigned int workers;
isc_timermgr_t timgr;
isc_timer_t ti1, ti2;
......@@ -63,12 +63,12 @@ main(int argc, char *argv[]) {
INSIST(mem_context_create(0, 0, &mctx) == 0);
INSIST(task_manager_create(mctx, workers, 0, &manager) == workers);
INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) == workers);
INSIST(task_create(manager, my_shutdown, "1", 0, &t1));
INSIST(task_create(manager, my_shutdown, "2", 0, &t2));
INSIST(task_create(manager, my_shutdown, "3", 0, &t3));
INSIST(task_create(manager, my_shutdown, "4", 0, &t4));
INSIST(isc_task_create(manager, my_shutdown, "1", 0, &t1));
INSIST(isc_task_create(manager, my_shutdown, "2", 0, &t2));
INSIST(isc_task_create(manager, my_shutdown, "3", 0, &t3));
INSIST(isc_task_create(manager, my_shutdown, "4", 0, &t4));
timgr = NULL;
INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS);
......@@ -89,64 +89,64 @@ main(int argc, char *argv[]) {
printf("task 2 = %p\n", t2);
sleep(2);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
task_send_event(t1, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "2",
sizeof *event);
task_send_event(t2, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "3",
sizeof *event);
task_send_event(t3, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "4",
sizeof *event);
task_send_event(t4, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "2",
sizeof *event);
task_send_event(t2, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "3",
sizeof *event);
task_send_event(t3, &event);
event = task_event_allocate(mctx, main, 1, my_callback, "4",
sizeof *event);
task_send_event(t4, &event);
task_purge_events(t3, NULL, 0);
task_detach(&t1);
task_detach(&t2);
task_detach(&t3);
task_detach(&t4);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "1",
sizeof *event);
isc_task_send(t1, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "2",
sizeof *event);
isc_task_send(t2, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "3",
sizeof *event);
isc_task_send(t3, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "4",
sizeof *event);
isc_task_send(t4, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "2",
sizeof *event);
isc_task_send(t2, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "3",
sizeof *event);
isc_task_send(t3, &event);
event = isc_event_allocate(mctx, main, 1, my_callback, "4",
sizeof *event);
isc_task_send(t4, &event);
isc_task_purge(t3, NULL, 0);
isc_task_detach(&t1);
isc_task_detach(&t2);
isc_task_detach(&t3);
isc_task_detach(&t4);
sleep(10);
printf("destroy\n");
isc_timer_detach(&ti1);
isc_timer_detach(&ti2);
isc_timermgr_destroy(&timgr);
task_manager_destroy(&manager);
isc_taskmgr_destroy(&manager);
printf("destroyed\n");
mem_stats(mctx, stdout);
......
......@@ -12,12 +12,12 @@
#include <isc/timer.h>
mem_context_t mctx = NULL;
task_t t1, t2, t3;
isc_task_t t1, t2, t3;
isc_timer_t ti1, ti2, ti3;
int tick_count = 0;
static isc_boolean_t
shutdown_task(task_t task, task_event_t event) {
shutdown_task(isc_task_t task, isc_event_t event) {
char *name = event->arg;
printf("task %p shutdown %s\n", task, name);
......@@ -25,7 +25,7 @@ shutdown_task(task_t task, task_event_t event) {
}
static isc_boolean_t
tick(task_t task, task_event_t event)
tick(isc_task_t task, isc_event_t event)
{
char *name = event->arg;
......@@ -56,7 +56,7 @@ tick(task_t task, task_event_t event)
}
static isc_boolean_t
timeout(task_t task, task_event_t event)
timeout(isc_task_t task, isc_event_t event)
{
char *name = event->arg;
char *type;
......@@ -79,7 +79,7 @@ timeout(task_t task, task_event_t event)
void
main(int argc, char *argv[]) {
task_manager_t manager = NULL;
isc_taskmgr_t manager = NULL;
isc_timermgr_t timgr = NULL;
unsigned int workers;
os_time_t expires, interval, now;
......@@ -91,10 +91,10 @@ main(int argc, char *argv[]) {
printf("%d workers\n", workers);
INSIST(mem_context_create(0, 0, &mctx) == 0);
INSIST(task_manager_create(mctx, workers, 0, &manager) == workers);
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(isc_taskmgr_create(mctx, workers, 0, &manager) == workers);
INSIST(isc_task_create(manager, shutdown_task, "1", 0, &t1));
INSIST(isc_task_create(manager, shutdown_task, "2", 0, &t2));
INSIST(isc_task_create(manager, shutdown_task, "3", 0, &t3));
INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS);
printf("task 1: %p\n", t1);
......@@ -123,9 +123,9 @@ main(int argc, char *argv[]) {
INSIST(isc_timer_create(timgr, isc_timertype_once, expires, interval,
t3, timeout, "3", &ti3) == ISC_R_SUCCESS);
task_detach(&t1);
task_detach(&t2);
task_detach(&t3);
isc_task_detach(&t1);
isc_task_detach(&t2);
isc_task_detach(&t3);
sleep(15);
printf("destroy\n");
......@@ -134,7 +134,7 @@ main(int argc, char *argv[]) {
isc_timer_detach(&ti3);
sleep(2);
isc_timermgr_destroy(&timgr);
task_manager_destroy(&manager);
isc_taskmgr_destroy(&manager);
printf("destroyed\n");
mem_stats(mctx, stdout);
......
#ifndef TASK_H
#define TASK_H 1
#ifndef ISC_TASK_H
#define ISC_TASK_H 1
#include <stddef.h>
......@@ -14,9 +14,9 @@
*** Core Types.
***/
typedef struct task_event * task_event_t;
typedef struct task * task_t;
typedef struct task_manager * task_manager_t;
typedef struct isc_event * isc_event_t;
typedef struct isc_task * isc_task_t;
typedef struct isc_taskmgr * isc_taskmgr_t;
/***
......@@ -28,64 +28,65 @@ typedef struct task_manager * task_manager_t;
*
* Type 0 means "any type".
*/
typedef int task_eventtype_t;
typedef int isc_eventtype_t;
typedef isc_boolean_t (*task_action_t)(task_t, task_event_t);
typedef isc_boolean_t (*isc_taskaction_t)(isc_task_t, isc_event_t);
/*
* This structure is public because "subclassing" it may be useful when
* defining new event types.
*/
struct task_event {
struct isc_event {
mem_context_t mctx;
size_t size;
void * sender;
task_eventtype_t type;
task_action_t action;
isc_eventtype_t type;
isc_taskaction_t action;
void * arg;
LINK(struct task_event) link;
LINK(struct isc_event) link;
};
#define TASK_EVENT_ANYEVENT 0
#define TASK_EVENT_SHUTDOWN (-1)
#define ISC_TASKEVENT_ANYEVENT 0
#define ISC_TASKEVENT_SHUTDOWN (-1)
typedef LIST(struct task_event) task_eventlist_t;
typedef LIST(struct isc_event) isc_eventlist_t;
task_event_t task_event_allocate(mem_context_t,
void *,
task_eventtype_t,
task_action_t,
void *arg,
size_t);
void task_event_free(task_event_t *);
isc_event_t isc_event_allocate(mem_context_t,
void *,
isc_eventtype_t,
isc_taskaction_t,
void *arg,
size_t);
void isc_event_free(isc_event_t *);
/***
*** Tasks.
***/
isc_boolean_t task_create(task_manager_t,
task_action_t,
isc_boolean_t isc_task_create(isc_taskmgr_t,
isc_taskaction_t,
void *,
unsigned int,
task_t *);
void task_attach(task_t, task_t *);
void task_detach(task_t *);
isc_boolean_t task_send_event(task_t,
task_event_t *);
void task_purge_events(task_t, void *,
task_eventtype_t);
void task_shutdown(task_t);
void task_destroy(task_t *);
isc_task_t *);
void isc_task_attach(isc_task_t,
isc_task_t *);
void isc_task_detach(isc_task_t *);
isc_boolean_t isc_task_send(isc_task_t,
isc_event_t *);
void isc_task_purge(isc_task_t, void *,
isc_eventtype_t);
void isc_task_shutdown(isc_task_t);
void isc_task_destroy(isc_task_t *);
/***
*** Task Manager.
***/
unsigned int task_manager_create(mem_context_t,
unsigned int,
unsigned int,
task_manager_t *);
void task_manager_destroy(task_manager_t *);
unsigned int isc_taskmgr_create(mem_context_t,
unsigned int,
unsigned int,
isc_taskmgr_t *);
void isc_taskmgr_destroy(isc_taskmgr_t *);
#endif /* TASK_H */
#endif /* ISC_TASK_H */
......@@ -72,7 +72,7 @@ typedef enum {
} isc_timertype_t;
typedef struct isc_timerevent {
struct task_event common;
struct isc_event common;
/* XXX Anything else? XXX */
} *isc_timerevent_t;
......@@ -93,8 +93,8 @@ 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,
isc_task_t task,
isc_taskaction_t action,
void *arg,
isc_timer_t *timerp);
/*
......
......@@ -26,7 +26,7 @@
#define WAIT(cvp, lp) INSIST(os_condition_wait((cvp), (lp)))
#define BROADCAST(cvp) INSIST(os_condition_broadcast((cvp)))
#ifdef TASK_TRACE
#ifdef ISC_TASK_TRACE
#define XTRACE(m) printf("%s task %p thread %p\n", (m), \
task, os_thread_self())
#else
......@@ -47,36 +47,36 @@ typedef enum {
#define VALID_TASK(t) ((t) != NULL && \
(t)->magic == TASK_MAGIC)
struct task {
struct isc_task {
/* Not locked. */
unsigned int magic;
task_manager_t manager;
isc_taskmgr_t manager;
os_mutex_t lock;
/* Locked by task lock. */
task_state_t state;
unsigned int references;
task_eventlist_t events;
isc_eventlist_t events;
unsigned int quantum;
isc_boolean_t enqueue_allowed;
task_event_t shutdown_event;
isc_event_t shutdown_event;
/* Locked by task manager lock. */
LINK(struct task) link;
LINK(struct task) ready_link;
LINK(struct isc_task) link;
LINK(struct isc_task) ready_link;
};
#define TASK_MANAGER_MAGIC 0x54534B4DU /* TSKM. */
#define VALID_MANAGER(m) ((m) != NULL && \
(m)->magic == TASK_MANAGER_MAGIC)
struct task_manager {
struct isc_taskmgr {
/* Not locked. */
unsigned int magic;
mem_context_t mctx;
os_mutex_t lock;
/* Locked by task manager lock. */
unsigned int default_quantum;
LIST(struct task) tasks;
LIST(struct task) ready_tasks;
LIST(struct isc_task) tasks;
LIST(struct isc_task) ready_tasks;
os_condition_t work_available;
isc_boolean_t exiting;
unsigned int workers;
......@@ -91,11 +91,11 @@ struct task_manager {
*** Events.
***/
static inline task_event_t
event_allocate(mem_context_t mctx, void *sender, task_eventtype_t type,
task_action_t action, void *arg, size_t size)
static inline isc_event_t
event_allocate(mem_context_t mctx, void *sender, isc_eventtype_t type,
isc_taskaction_t action, void *arg, size_t size)
{
task_event_t event;
isc_event_t event;
event = mem_get(mctx, size);
if (event == NULL)
......@@ -110,11 +110,11 @@ event_allocate(mem_context_t mctx, void *sender, task_eventtype_t type,
return (event);
}
task_event_t
task_event_allocate(mem_context_t mctx, void *sender, task_eventtype_t type,
task_action_t action, void *arg, size_t size)
isc_event_t
isc_event_allocate(mem_context_t mctx, void *sender, isc_eventtype_t type,
isc_taskaction_t action, void *arg, size_t size)
{
if (size < sizeof (struct task_event))
if (size < sizeof (struct isc_event))
return (NULL);
if (type < 0)
return (NULL);
......@@ -125,8 +125,8 @@ task_event_allocate(mem_context_t mctx, void *sender, task_eventtype_t type,
}
void
task_event_free(task_event_t *eventp) {
task_event_t event;
isc_event_free(isc_event_t *eventp) {
isc_event_t event;
REQUIRE(eventp != NULL);
event = *eventp;
......@@ -142,8 +142,8 @@ task_event_free(task_event_t *eventp) {
***/
static void
task_free(task_t task) {
task_manager_t manager = task->manager;
task_free(isc_task_t task) {
isc_taskmgr_t manager = task->manager;
XTRACE("free task");
REQUIRE(EMPTY(task->events));
......@@ -162,16 +162,16 @@ task_free(task_t task) {
UNLOCK(&manager->lock);
(void)os_mutex_destroy(&task->lock);
if (task->shutdown_event != NULL)
task_event_free(&task->shutdown_event);
isc_event_free(&task->shutdown_event);
task->magic = 0;
mem_put(manager->mctx, task, sizeof *task);
}
isc_boolean_t
task_create(task_manager_t manager, task_action_t shutdown_action,
void *shutdown_arg, unsigned int quantum, task_t *taskp)
isc_task_create(isc_taskmgr_t manager, isc_taskaction_t shutdown_action,
void *shutdown_arg, unsigned int quantum, isc_task_t *taskp)
{
task_t task;
isc_task_t task;
REQUIRE(VALID_MANAGER(manager));
REQUIRE(taskp != NULL && *taskp == NULL);
......@@ -193,7 +193,7 @@ task_create(task_manager_t manager, task_action_t shutdown_action,
task->enqueue_allowed = ISC_TRUE;
task->shutdown_event = event_allocate(manager->mctx,
NULL,
TASK_EVENT_SHUTDOWN,
ISC_TASKEVENT_SHUTDOWN,
shutdown_action,
shutdown_arg,
sizeof *task->shutdown_event);
......@@ -217,7 +217,7 @@ task_create(task_manager_t manager, task_action_t shutdown_action,
}
void
task_attach(task_t task, task_t *taskp) {
isc_task_attach(isc_task_t task, isc_task_t *taskp) {
REQUIRE(VALID_TASK(task));
REQUIRE(taskp != NULL && *taskp == NULL);
......@@ -230,11 +230,11 @@ task_attach(task_t task, task_t *taskp) {
}
void
task_detach(task_t *taskp) {
isc_task_detach(isc_task_t *taskp) {
isc_boolean_t free_task = ISC_FALSE;
task_t task;
isc_task_t task;
XTRACE("task_detach");
XTRACE("isc_task_detach");
REQUIRE(taskp != NULL);
task = *taskp;
......@@ -254,10 +254,10 @@ task_detach(task_t *taskp) {
}
isc_boolean_t
task_send_event(task_t task, task_event_t *eventp) {
isc_task_send(isc_task_t task, isc_event_t *eventp) {
isc_boolean_t was_idle = ISC_FALSE;
isc_boolean_t discard = ISC_FALSE;
task_event_t event;
isc_event_t event;
REQUIRE(VALID_TASK(task));
REQUIRE(eventp != NULL);
......@@ -287,14 +287,14 @@ task_send_event(task_t task, task_event_t *eventp) {
UNLOCK(&task->lock);
if (discard) {
task_event_free(&event);
isc_event_free(&event);
*eventp = NULL;
return (ISC_TRUE);
}
if (was_idle) {
isc_boolean_t need_wakeup = ISC_FALSE;
task_manager_t manager;
isc_taskmgr_t manager;
/*
* We need to add this task to the ready queue.
......@@ -339,9 +339,9 @@ task_send_event(task_t task, task_event_t *eventp) {
}
void
task_purge_events(task_t task, void *sender, task_eventtype_t type) {
task_event_t event, next_event;
task_eventlist_t purgeable;
isc_task_purge(isc_task_t task, void *sender, isc_eventtype_t type) {
isc_event_t event, next_event;
isc_eventlist_t purgeable;
REQUIRE(VALID_TASK(task));
REQUIRE(type >= 0);
......@@ -371,19 +371,19 @@ task_purge_events(task_t task, void *sender, task_eventtype_t type) {
event != NULL;
event = next_event) {
next_event = NEXT(event, link);
task_event_free(&event);
isc_event_free(&event);
}
}
void
task_shutdown(task_t task) {
isc_task_shutdown(isc_task_t task) {
isc_boolean_t was_idle = ISC_FALSE;
isc_boolean_t discard = ISC_FALSE;
REQUIRE(VALID_TASK(task));
/*
* This routine is very similar to task_send_event() above.
* This routine is very similar to isc_task_send_event() above.
*/
LOCK(&task->lock);
......@@ -408,7 +408,7 @@ task_shutdown(task_t task) {
if (was_idle) {
isc_boolean_t need_wakeup = ISC_FALSE;
task_manager_t manager;
isc_taskmgr_t manager;
manager = task->manager;
INSIST(VALID_MANAGER(manager));
......@@ -424,12 +424,12 @@ task_shutdown(task_t task) {
}