2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Update netmgr, tasks, and applications to use isc_loopmgr

Previously:

* applications were using isc_app as the base unit for running the
  application and signal handling.

* networking was handled in the netmgr layer, which would start a
  number of threads, each with a uv_loop event loop.

* task/event handling was done in the isc_task unit, which used
  netmgr event loops to run the isc_event calls.

In this refactoring:

* the network manager now uses isc_loop instead of maintaining its
  own worker threads and event loops.

* the taskmgr that manages isc_task instances now also uses isc_loopmgr,
  and every isc_task runs on a specific isc_loop bound to the specific
  thread.

* applications have been updated as necessary to use the new API.

* new ISC_LOOP_TEST macros have been added to enable unit tests to
  run isc_loop event loops. unit tests have been updated to use this
  where needed.
This commit is contained in:
Ondřej Surý
2022-07-26 13:03:45 +02:00
parent 49b149f5fd
commit b69e783164
90 changed files with 4056 additions and 6642 deletions

View File

@@ -107,6 +107,7 @@ struct cache_cleaner {
dns_cache_t *cache;
isc_task_t *task;
isc_event_t *shutdown_event;
isc_event_t *resched_event; /*% Sent by cleaner task to
* itself to reschedule */
isc_event_t *overmem_event;
@@ -259,7 +260,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
}
if (taskmgr != NULL) {
dbtask = NULL;
result = isc_task_create(taskmgr, 1, &dbtask, 0);
result = isc_task_create(taskmgr, &dbtask, 0);
if (result != ISC_R_SUCCESS) {
goto cleanup_db;
}
@@ -337,6 +338,10 @@ cache_free(dns_cache_t *cache) {
isc_event_free(&cache->cleaner.resched_event);
}
if (cache->cleaner.shutdown_event != NULL) {
isc_event_free(&cache->cleaner.shutdown_event);
}
if (cache->cleaner.iterator != NULL) {
dns_dbiterator_destroy(&cache->cleaner.iterator);
}
@@ -406,16 +411,9 @@ dns_cache_detach(dns_cache_t **cachep) {
if (isc_refcount_decrement(&cache->references) == 1) {
cache->cleaner.overmem = false;
/*
* If the cleaner task exists, let it free the cache.
*/
if (isc_refcount_decrement(&cache->live_tasks) > 1) {
isc_event_t *event = isc_event_allocate(
cache->mctx, &cache->cleaner,
DNS_EVENT_CACHESHUTDOWN,
cleaner_shutdown_action, &cache->cleaner,
sizeof(*event));
isc_task_send(cache->cleaner.task, &event);
isc_task_send(cache->cleaner.task,
&cache->cleaner.shutdown_event);
} else {
cache_free(cache);
}
@@ -460,27 +458,32 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
cleaner->replaceiterator = false;
cleaner->task = NULL;
cleaner->shutdown_event = NULL;
cleaner->resched_event = NULL;
cleaner->overmem_event = NULL;
result = dns_db_createiterator(cleaner->cache->db, false,
&cleaner->iterator);
if (result != ISC_R_SUCCESS) {
goto cleanup;
goto cleanup_mutex;
}
if (taskmgr != NULL) {
result = isc_task_create(taskmgr, 1, &cleaner->task, 0);
result = isc_task_create(taskmgr, &cleaner->task, 0);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_task_create() failed: %s",
isc_result_totext(result));
result = ISC_R_UNEXPECTED;
goto cleanup;
goto cleanup_iterator;
}
isc_refcount_increment(&cleaner->cache->live_tasks);
isc_task_setname(cleaner->task, "cachecleaner", cleaner);
cleaner->shutdown_event = isc_event_allocate(
cache->mctx, cleaner, DNS_EVENT_CACHESHUTDOWN,
cleaner_shutdown_action, cleaner, sizeof(isc_event_t));
cleaner->resched_event = isc_event_allocate(
cache->mctx, cleaner, DNS_EVENT_CACHECLEAN,
incremental_cleaning_action, cleaner,
@@ -493,19 +496,9 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
return (ISC_R_SUCCESS);
cleanup:
if (cleaner->overmem_event != NULL) {
isc_event_free(&cleaner->overmem_event);
}
if (cleaner->resched_event != NULL) {
isc_event_free(&cleaner->resched_event);
}
if (cleaner->task != NULL) {
isc_task_detach(&cleaner->task);
}
if (cleaner->iterator != NULL) {
dns_dbiterator_destroy(&cleaner->iterator);
}
cleanup_iterator:
dns_dbiterator_destroy(&cleaner->iterator);
cleanup_mutex:
isc_mutex_destroy(&cleaner->lock);
return (result);
@@ -956,8 +949,8 @@ cleaner_shutdown_action(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event);
}
/* Make sure we don't reschedule anymore. */
(void)isc_task_purgeevent(task, cache->cleaner.resched_event);
/* FIXME: Make sure we don't reschedule anymore. */
/* (void)isc_task_purgeevent(task, cache->cleaner.resched_event); */
isc_refcount_decrementz(&cache->live_tasks);