From 64b1a68e10673baf0f559e8f85f890181c99b06c Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Wed, 12 Apr 2000 01:34:16 +0000 Subject: [PATCH] isc_task_create() no longer takes an mctx. isc_task_mem() has been eliminated. Use memory context reference counting. --- lib/isc/include/isc/task.h | 20 ++----------------- lib/isc/task.c | 39 +++++++++++++++----------------------- 2 files changed, 17 insertions(+), 42 deletions(-) diff --git a/lib/isc/include/isc/task.h b/lib/isc/include/isc/task.h index 24e8c0e7f3..7566f53a72 100644 --- a/lib/isc/include/isc/task.h +++ b/lib/isc/include/isc/task.h @@ -73,8 +73,8 @@ ISC_LANG_BEGINDECLS *****/ isc_result_t -isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, - unsigned int quantum, isc_task_t **taskp); +isc_task_create(isc_taskmgr_t *manager, unsigned int quantum, + isc_task_t **taskp); /* * Create a task. * @@ -93,8 +93,6 @@ isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, * * 'manager' is a valid task manager. * - * 'mctx' is a valid memory context. - * * taskp != NULL && *taskp == NULL * * Ensures: @@ -148,20 +146,6 @@ isc_task_detach(isc_task_t **taskp); * All resources used by the task will be freed. */ -isc_mem_t * -isc_task_mem(isc_task_t *task); -/* - * Get the task's memory context. - * - * Requires: - * - * 'task' is a valid task. - * - * Returns: - * - * The memory context specified when the task was created. - */ - void isc_task_send(isc_task_t *task, isc_event_t **eventp); /* diff --git a/lib/isc/task.c b/lib/isc/task.c index f2673078a4..438be43ce3 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -145,11 +145,11 @@ task_finished(isc_task_t *task) { (void)isc_mutex_destroy(&task->lock); task->magic = 0; - isc_mem_put(task->mctx, task, sizeof *task); + isc_mem_put(manager->mctx, task, sizeof *task); } isc_result_t -isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, unsigned int quantum, +isc_task_create(isc_taskmgr_t *manager, unsigned int quantum, isc_task_t **taskp) { isc_task_t *task; @@ -158,16 +158,13 @@ isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, unsigned int quantum, REQUIRE(VALID_MANAGER(manager)); REQUIRE(taskp != NULL && *taskp == NULL); - if (mctx == NULL) - mctx = manager->mctx; - task = isc_mem_get(mctx, sizeof *task); + task = isc_mem_get(manager->mctx, sizeof *task); if (task == NULL) return (ISC_R_NOMEMORY); XTRACE("create"); task->manager = manager; - task->mctx = mctx; if (isc_mutex_init(&task->lock) != ISC_R_SUCCESS) { - isc_mem_put(mctx, task, sizeof *task); + isc_mem_put(manager->mctx, task, sizeof *task); UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_mutex_init() failed"); return (ISC_R_UNEXPECTED); @@ -197,7 +194,7 @@ isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, unsigned int quantum, if (exiting) { isc_mutex_destroy(&task->lock); - isc_mem_put(mctx, task, sizeof *task); + isc_mem_put(manager->mctx, task, sizeof *task); return (ISC_R_SHUTTINGDOWN); } @@ -333,18 +330,6 @@ isc_task_detach(isc_task_t **taskp) { *taskp = NULL; } -isc_mem_t * -isc_task_mem(isc_task_t *task) { - - /* - * Get the task's memory context. - */ - - REQUIRE(VALID_TASK(task)); - - return (task->mctx); -} - static inline isc_boolean_t task_send(isc_task_t *task, isc_event_t **eventp) { isc_boolean_t was_idle = ISC_FALSE; @@ -622,7 +607,7 @@ isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg) { REQUIRE(VALID_TASK(task)); REQUIRE(action != NULL); - event = isc_event_allocate(task->mctx, + event = isc_event_allocate(task->manager->mctx, NULL, ISC_TASKEVENT_SHUTDOWN, action, @@ -640,7 +625,7 @@ isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg) { UNLOCK(&task->lock); if (disallowed) - isc_mem_put(task->mctx, event, sizeof *event); + isc_mem_put(task->manager->mctx, event, sizeof *event); return (result); } @@ -924,12 +909,16 @@ run(void *uap) { static void manager_free(isc_taskmgr_t *manager) { + isc_mem_t *mctx; + (void)isc_condition_destroy(&manager->work_available); (void)isc_mutex_destroy(&manager->lock); isc_mem_put(manager->mctx, manager->threads, manager->workers * sizeof (isc_thread_t)); manager->magic = 0; - isc_mem_put(manager->mctx, manager, sizeof *manager); + mctx = manager->mctx; + isc_mem_put(mctx, manager, sizeof *manager); + isc_mem_detach(&mctx); } isc_result_t @@ -951,7 +940,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers, if (manager == NULL) return (ISC_R_NOMEMORY); manager->magic = TASK_MANAGER_MAGIC; - manager->mctx = mctx; + manager->mctx = NULL; threads = isc_mem_get(mctx, workers * sizeof (isc_thread_t)); if (threads == NULL) { isc_mem_put(mctx, manager, sizeof *manager); @@ -982,6 +971,8 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers, manager->exiting = ISC_FALSE; manager->workers = 0; + isc_mem_attach(mctx, &manager->mctx); + LOCK(&manager->lock); /* * Start workers.