2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +00:00

start on cleanup timer/task

This commit is contained in:
Michael Graff
1999-10-25 22:53:15 +00:00
parent d65139063d
commit 3ac63b4720
3 changed files with 94 additions and 18 deletions

View File

@@ -48,7 +48,7 @@ struct client {
}; };
isc_mem_t *mctx; isc_mem_t *mctx;
isc_taskmgr_t *manager; isc_taskmgr_t *taskmgr;
isc_socketmgr_t *socketmgr; isc_socketmgr_t *socketmgr;
isc_timermgr_t *timermgr; isc_timermgr_t *timermgr;
isc_task_t *t1, *t2; isc_task_t *t1, *t2;
@@ -249,8 +249,8 @@ create_managers(void)
{ {
isc_result_t result; isc_result_t result;
manager = NULL; taskmgr = NULL;
result = isc_taskmgr_create(mctx, 2, 0, &manager); result = isc_taskmgr_create(mctx, 2, 0, &taskmgr);
check_result(result, "isc_taskmgr_create"); check_result(result, "isc_taskmgr_create");
timermgr = NULL; timermgr = NULL;
@@ -291,7 +291,7 @@ create_view(void)
* XXXRTH hardwired number of tasks. Also, we'll need to * XXXRTH hardwired number of tasks. Also, we'll need to
* see if we are dealing with a shared dispatcher in this view. * see if we are dealing with a shared dispatcher in this view.
*/ */
result = dns_view_createresolver(view, manager, 16, socketmgr, result = dns_view_createresolver(view, taskmgr, 16, socketmgr,
timermgr, NULL); timermgr, NULL);
check_result(result, "dns_view_createresolver"); check_result(result, "dns_view_createresolver");
@@ -425,10 +425,10 @@ main(int argc, char **argv)
create_managers(); create_managers();
t1 = NULL; t1 = NULL;
result = isc_task_create(manager, NULL, 0, &t1); result = isc_task_create(taskmgr, NULL, 0, &t1);
check_result(result, "isc_task_create t1"); check_result(result, "isc_task_create t1");
t2 = NULL; t2 = NULL;
result = isc_task_create(manager, NULL, 0, &t2); result = isc_task_create(taskmgr, NULL, 0, &t2);
check_result(result, "isc_task_create t2"); check_result(result, "isc_task_create t2");
printf("task 1 = %p\n", t1); printf("task 1 = %p\n", t1);
@@ -440,7 +440,7 @@ main(int argc, char **argv)
* Create the address database. * Create the address database.
*/ */
adb = NULL; adb = NULL;
result = dns_adb_create(mctx, view, &adb); result = dns_adb_create(mctx, view, timermgr, taskmgr, &adb);
check_result(result, "dns_adb_create"); check_result(result, "dns_adb_create");
/* /*
@@ -484,7 +484,7 @@ main(int argc, char **argv)
isc_timermgr_destroy(&timermgr); isc_timermgr_destroy(&timermgr);
fprintf(stderr, "Destroying task manager\n"); fprintf(stderr, "Destroying task manager\n");
isc_taskmgr_destroy(&manager); isc_taskmgr_destroy(&taskmgr);
isc_mem_stats(mctx, stdout); isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx); isc_mem_destroy(&mctx);

View File

@@ -37,6 +37,7 @@
#include <isc/mutex.h> #include <isc/mutex.h>
#include <isc/mutexblock.h> #include <isc/mutexblock.h>
#include <isc/random.h> #include <isc/random.h>
#include <isc/timer.h>
#include <dns/adb.h> #include <dns/adb.h>
#include <dns/db.h> #include <dns/db.h>
@@ -70,6 +71,8 @@
#define DNS_ADBNAMELIST_LENGTH 32 /* how many buckets for names */ #define DNS_ADBNAMELIST_LENGTH 32 /* how many buckets for names */
#define DNS_ADBENTRYLIST_LENGTH 32 /* how many buckets for addresses */ #define DNS_ADBENTRYLIST_LENGTH 32 /* how many buckets for addresses */
#define CLEAN_SECONDS 20 /* clean this many seconds initially */
#define FREE_ITEMS 16 /* free count for memory pools */ #define FREE_ITEMS 16 /* free count for memory pools */
#define FILL_COUNT 8 /* fill count for memory pools */ #define FILL_COUNT 8 /* fill count for memory pools */
@@ -89,7 +92,10 @@ struct dns_adb {
isc_mem_t *mctx; isc_mem_t *mctx;
dns_view_t *view; dns_view_t *view;
isc_timermgr_t *timermgr; isc_timermgr_t *timermgr;
isc_timer_t *timer;
isc_taskmgr_t *taskmgr; isc_taskmgr_t *taskmgr;
isc_task_t *task;
isc_interval_t tick_interval;
unsigned int irefcnt; unsigned int irefcnt;
unsigned int erefcnt; unsigned int erefcnt;
@@ -227,8 +233,8 @@ static void clean_handles_at_name(dns_adbname_t *, isc_eventtype_t);
static isc_result_t construct_name(dns_adb_t *, dns_adbhandle_t *, static isc_result_t construct_name(dns_adb_t *, dns_adbhandle_t *,
dns_name_t *, dns_name_t *, dns_name_t *, dns_name_t *,
dns_adbname_t *, int, isc_stdtime_t); dns_adbname_t *, int, isc_stdtime_t);
static inline isc_boolean_t check_exit(dns_adb_t *); static inline isc_boolean_t check_exit(dns_adb_t *);
static void timer_cleanup(isc_task_t *, isc_event_t *);
static inline void static inline void
violate_locking_hierarchy(isc_mutex_t *have, isc_mutex_t *want) violate_locking_hierarchy(isc_mutex_t *have, isc_mutex_t *want)
@@ -974,11 +980,51 @@ copy_namehook_list(dns_adb_t *adb, dns_adbhandle_t *handle,
UNLOCK(&adb->entrylocks[bucket]); UNLOCK(&adb->entrylocks[bucket]);
} }
/*
* ADB must be locked
*/
static void
cleanup(dns_adb_t *adb)
{
}
static void
timer_cleanup(isc_task_t *task, isc_event_t *ev)
{
dns_adb_t *adb;
isc_result_t result;
adb = ev->arg;
INSIST(DNS_ADB_VALID(adb));
printf("Tick!\n");
LOCK(&adb->lock);
/*
* Call our cleanup routine.
*/
cleanup(adb);
/*
* Reset the timer.
*/
result = isc_timer_reset(adb->timer, isc_timertype_once, NULL,
&adb->tick_interval, ISC_FALSE);
UNLOCK(&adb->lock);
isc_event_free(&ev);
}
static void static void
destroy(dns_adb_t *adb) destroy(dns_adb_t *adb)
{ {
adb->magic = 0; adb->magic = 0;
isc_timer_detach(&adb->timer);
isc_task_detach(&adb->task);
isc_mempool_destroy(&adb->nmp); isc_mempool_destroy(&adb->nmp);
isc_mempool_destroy(&adb->nhmp); isc_mempool_destroy(&adb->nhmp);
isc_mempool_destroy(&adb->zimp); isc_mempool_destroy(&adb->zimp);
@@ -990,6 +1036,11 @@ destroy(dns_adb_t *adb)
isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH); isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH); isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
/*
* At this point, nothing can possibly be running, so we can safely
* kill the locks.
*/
UNLOCK(&adb->lock);
isc_mutex_destroy(&adb->lock); isc_mutex_destroy(&adb->lock);
isc_mutex_destroy(&adb->mplock); isc_mutex_destroy(&adb->mplock);
@@ -1012,6 +1063,9 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
int i; int i;
REQUIRE(mem != NULL); REQUIRE(mem != NULL);
REQUIRE(view != NULL);
REQUIRE(timermgr != NULL);
REQUIRE(taskmgr != NULL);
REQUIRE(newadb != NULL && *newadb == NULL); REQUIRE(newadb != NULL && *newadb == NULL);
adb = isc_mem_get(mem, sizeof (dns_adb_t)); adb = isc_mem_get(mem, sizeof (dns_adb_t));
@@ -1032,6 +1086,12 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
adb->ahmp = NULL; adb->ahmp = NULL;
adb->aimp = NULL; adb->aimp = NULL;
adb->afmp = NULL; adb->afmp = NULL;
adb->task = NULL;
adb->timer = NULL;
adb->mctx = mem;
adb->view = view;
adb->timermgr = timermgr;
adb->taskmgr = taskmgr;
result = isc_random_init(&adb->rand); result = isc_random_init(&adb->rand);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
@@ -1090,18 +1150,33 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
#undef MPINIT #undef MPINIT
/*
* Allocate a timer and a task for our periodic cleanup.
*/
result = isc_task_create(adb->taskmgr, adb->mctx, 0, &adb->task);
if (result != ISC_R_SUCCESS)
goto fail3;
isc_interval_set(&adb->tick_interval, CLEAN_SECONDS, 0);
result = isc_timer_create(adb->timermgr, isc_timertype_once,
NULL, &adb->tick_interval, adb->task,
timer_cleanup, adb, &adb->timer);
if (result != ISC_R_SUCCESS)
goto fail3;
/* /*
* Normal return. * Normal return.
*/ */
adb->mctx = mem;
adb->view = view;
adb->timermgr = timermgr;
adb->taskmgr = taskmgr;
adb->magic = DNS_ADB_MAGIC; adb->magic = DNS_ADB_MAGIC;
*newadb = adb; *newadb = adb;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
fail3: /* clean up entrylocks */ fail3:
if (adb->task != NULL)
isc_task_detach(&adb->task);
if (adb->timer != NULL)
isc_timer_detach(&adb->timer);
/* clean up entrylocks */
isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH); isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
fail2: /* clean up namelocks */ fail2: /* clean up namelocks */
@@ -1152,10 +1227,11 @@ dns_adb_detach(dns_adb_t **adbx)
if (adb->erefcnt == 0) if (adb->erefcnt == 0)
shutdown_names(adb, ISC_TRUE); shutdown_names(adb, ISC_TRUE);
kill = check_exit(adb); kill = check_exit(adb);
UNLOCK(&adb->lock);
if (kill) if (kill)
destroy(adb); destroy(adb);
else
UNLOCK(&adb->lock);
} }
isc_result_t isc_result_t
@@ -1559,10 +1635,11 @@ dns_adb_done(dns_adbhandle_t **handlep)
LOCK(&adb->lock); LOCK(&adb->lock);
free_adbhandle(adb, &handle); free_adbhandle(adb, &handle);
kill = check_exit(adb); kill = check_exit(adb);
UNLOCK(&adb->lock);
if (kill) if (kill)
destroy(adb); destroy(adb);
else
UNLOCK(&adb->lock);
} }
void void

View File

@@ -198,8 +198,7 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *tmgr,
* *
* 'view' be a pointer to a valid view. * 'view' be a pointer to a valid view.
* *
* 'tmgr' be a pointer to a valid timer manager. If this is NULL, * 'tmgr' be a pointer to a valid timer manager.
* no periodic cleaning will ever occur.
* *
* 'newadb' != NULL && '*newadb' == NULL. * 'newadb' != NULL && '*newadb' == NULL.
* *