2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 05:28:00 +00:00

isc_task_create() no longer takes an mctx.

isc_task_mem() has been eliminated.
Use memory context reference counting.
This commit is contained in:
Bob Halley 2000-04-12 01:34:16 +00:00
parent 3886e748a4
commit 64b1a68e10
2 changed files with 17 additions and 42 deletions

View File

@ -73,8 +73,8 @@ ISC_LANG_BEGINDECLS
*****/ *****/
isc_result_t isc_result_t
isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
unsigned int quantum, isc_task_t **taskp); isc_task_t **taskp);
/* /*
* Create a task. * Create a task.
* *
@ -93,8 +93,6 @@ isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx,
* *
* 'manager' is a valid task manager. * 'manager' is a valid task manager.
* *
* 'mctx' is a valid memory context.
*
* taskp != NULL && *taskp == NULL * taskp != NULL && *taskp == NULL
* *
* Ensures: * Ensures:
@ -148,20 +146,6 @@ isc_task_detach(isc_task_t **taskp);
* All resources used by the task will be freed. * 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 void
isc_task_send(isc_task_t *task, isc_event_t **eventp); isc_task_send(isc_task_t *task, isc_event_t **eventp);
/* /*

View File

@ -145,11 +145,11 @@ task_finished(isc_task_t *task) {
(void)isc_mutex_destroy(&task->lock); (void)isc_mutex_destroy(&task->lock);
task->magic = 0; task->magic = 0;
isc_mem_put(task->mctx, task, sizeof *task); isc_mem_put(manager->mctx, task, sizeof *task);
} }
isc_result_t 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 **taskp)
{ {
isc_task_t *task; 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(VALID_MANAGER(manager));
REQUIRE(taskp != NULL && *taskp == NULL); REQUIRE(taskp != NULL && *taskp == NULL);
if (mctx == NULL) task = isc_mem_get(manager->mctx, sizeof *task);
mctx = manager->mctx;
task = isc_mem_get(mctx, sizeof *task);
if (task == NULL) if (task == NULL)
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
XTRACE("create"); XTRACE("create");
task->manager = manager; task->manager = manager;
task->mctx = mctx;
if (isc_mutex_init(&task->lock) != ISC_R_SUCCESS) { 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__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed"); "isc_mutex_init() failed");
return (ISC_R_UNEXPECTED); return (ISC_R_UNEXPECTED);
@ -197,7 +194,7 @@ isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, unsigned int quantum,
if (exiting) { if (exiting) {
isc_mutex_destroy(&task->lock); isc_mutex_destroy(&task->lock);
isc_mem_put(mctx, task, sizeof *task); isc_mem_put(manager->mctx, task, sizeof *task);
return (ISC_R_SHUTTINGDOWN); return (ISC_R_SHUTTINGDOWN);
} }
@ -333,18 +330,6 @@ isc_task_detach(isc_task_t **taskp) {
*taskp = NULL; *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 static inline isc_boolean_t
task_send(isc_task_t *task, isc_event_t **eventp) { task_send(isc_task_t *task, isc_event_t **eventp) {
isc_boolean_t was_idle = ISC_FALSE; 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(VALID_TASK(task));
REQUIRE(action != NULL); REQUIRE(action != NULL);
event = isc_event_allocate(task->mctx, event = isc_event_allocate(task->manager->mctx,
NULL, NULL,
ISC_TASKEVENT_SHUTDOWN, ISC_TASKEVENT_SHUTDOWN,
action, action,
@ -640,7 +625,7 @@ isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg) {
UNLOCK(&task->lock); UNLOCK(&task->lock);
if (disallowed) if (disallowed)
isc_mem_put(task->mctx, event, sizeof *event); isc_mem_put(task->manager->mctx, event, sizeof *event);
return (result); return (result);
} }
@ -924,12 +909,16 @@ run(void *uap) {
static void static void
manager_free(isc_taskmgr_t *manager) { manager_free(isc_taskmgr_t *manager) {
isc_mem_t *mctx;
(void)isc_condition_destroy(&manager->work_available); (void)isc_condition_destroy(&manager->work_available);
(void)isc_mutex_destroy(&manager->lock); (void)isc_mutex_destroy(&manager->lock);
isc_mem_put(manager->mctx, manager->threads, isc_mem_put(manager->mctx, manager->threads,
manager->workers * sizeof (isc_thread_t)); manager->workers * sizeof (isc_thread_t));
manager->magic = 0; 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 isc_result_t
@ -951,7 +940,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
if (manager == NULL) if (manager == NULL)
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
manager->magic = TASK_MANAGER_MAGIC; manager->magic = TASK_MANAGER_MAGIC;
manager->mctx = mctx; manager->mctx = NULL;
threads = isc_mem_get(mctx, workers * sizeof (isc_thread_t)); threads = isc_mem_get(mctx, workers * sizeof (isc_thread_t));
if (threads == NULL) { if (threads == NULL) {
isc_mem_put(mctx, manager, sizeof *manager); 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->exiting = ISC_FALSE;
manager->workers = 0; manager->workers = 0;
isc_mem_attach(mctx, &manager->mctx);
LOCK(&manager->lock); LOCK(&manager->lock);
/* /*
* Start workers. * Start workers.