dns_view_attach(view, &(dns_view_t *){ NULL });
CHECK(dns_request_create(requestmgr, message, NULL, &peer, NULL, NULL,
- DNS_REQUESTOPT_TCP, NULL, 1, 0, 0,
- isc_loop_current(loopmgr), recvresponse,
- message, &request));
+ DNS_REQUESTOPT_TCP, NULL, 1, 0, 0, isc_loop(),
+ recvresponse, message, &request));
return;
cleanup:
dns_view_initsecroots(view);
CHECK(setup_dnsseckeys(NULL, view));
- CHECK(dns_view_createresolver(view, loopmgr, netmgr, 0,
- tlsctx_client_cache, dispatch, NULL));
+ CHECK(dns_view_createresolver(view, netmgr, 0, tlsctx_client_cache,
+ dispatch, NULL));
isc_stats_create(mctx, &resstats, dns_resstatscounter_max);
dns_resolver_setstats(view->resolver, resstats);
goto cleanup;
}
- CHECK(dns_view_createresolver(
- view, named_g_loopmgr, named_g_netmgr, resopts,
- named_g_server->tlsctx_client_cache, dispatch4, dispatch6));
+ CHECK(dns_view_createresolver(view, named_g_netmgr, resopts,
+ named_g_server->tlsctx_client_cache,
+ dispatch4, dispatch6));
if (resstats == NULL) {
isc_stats_create(mctx, &resstats, dns_resstatscounter_max);
/*
* Require the reconfiguration to happen always on the main loop
*/
- REQUIRE(isc_loop_current(named_g_loopmgr) == named_g_mainloop);
+ REQUIRE(isc_loop() == named_g_mainloop);
ISC_LIST_INIT(kasplist);
ISC_LIST_INIT(keystorelist);
named_server_t *server = (named_server_t *)arg;
dns_geoip_databases_t *geoip = NULL;
- dns_zonemgr_create(named_g_mctx, named_g_loopmgr, named_g_netmgr,
- &server->zonemgr);
+ dns_zonemgr_create(named_g_mctx, named_g_netmgr, &server->zonemgr);
CHECKFATAL(dns_dispatchmgr_create(named_g_mctx, named_g_loopmgr,
named_g_netmgr, &named_g_dispatchmgr),
dns_view_t *view;
dns_resolver_t *res;
- isc_loopmgr_t *loopmgr;
-
isc_refcount_t references;
dns_adbnamelist_t names_lru;
*/
void
-dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_loopmgr_t *loopmgr,
- dns_adb_t **newadb) {
+dns_adb_create(isc_mem_t *mem, dns_view_t *view, dns_adb_t **newadb) {
dns_adb_t *adb = NULL;
REQUIRE(mem != NULL);
adb = isc_mem_get(mem, sizeof(dns_adb_t));
*adb = (dns_adb_t){
- .loopmgr = loopmgr,
.names_lru = ISC_LIST_INITIALIZER,
.entries_lru = ISC_LIST_INITIALIZER,
};
*/
result = dns_resolver_createfetch(
adb->res, adbname->name, type, name, nameservers, NULL, NULL, 0,
- options, depth, qc, isc_loop_current(adb->loopmgr),
- fetch_callback, adbname, &fetch->rdataset, NULL, &fetch->fetch);
+ options, depth, qc, isc_loop(), fetch_callback, adbname,
+ &fetch->rdataset, NULL, &fetch->fetch);
if (result != ISC_R_SUCCESS) {
DP(ENTER_LEVEL, "fetch_name: createfetch failed with %s",
isc_result_totext(result));
isc_interval_set(&interval, 0, 0);
}
- catz->loop = isc_loop_current(catz->catzs->loopmgr);
+ catz->loop = isc_loop();
isc_timer_create(catz->loop, dns__catz_timer_cb, catz,
&catz->updatetimer);
}
static isc_result_t
-createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_loopmgr_t *loopmgr,
- isc_nm_t *nm, isc_tlsctx_cache_t *tlsctx_client_cache,
+createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_nm_t *nm,
+ isc_tlsctx_cache_t *tlsctx_client_cache,
dns_dispatchmgr_t *dispatchmgr, dns_dispatch_t *dispatchv4,
dns_dispatch_t *dispatchv6, dns_view_t **viewp) {
isc_result_t result;
/* Initialize view security roots */
dns_view_initsecroots(view);
- CHECK(dns_view_createresolver(view, loopmgr, nm, 0, tlsctx_client_cache,
+ CHECK(dns_view_createresolver(view, nm, 0, tlsctx_client_cache,
dispatchv4, dispatchv6));
CHECK(dns_db_create(mctx, CACHEDB_DEFAULT, dns_rootname,
dns_dbtype_cache, rdclass, 0, NULL,
isc_refcount_init(&client->references, 1);
/* Create the default view for class IN */
- result = createview(mctx, dns_rdataclass_in, loopmgr, nm,
- tlsctx_client_cache, client->dispatchmgr,
- dispatchv4, dispatchv6, &view);
+ result = createview(mctx, dns_rdataclass_in, nm, tlsctx_client_cache,
+ client->dispatchmgr, dispatchv4, dispatchv6, &view);
if (result != ISC_R_SUCCESS) {
goto cleanup_references;
}
*/
/****
-**** FUNCTIONS
-****/
+ **** FUNCTIONS
+ ****/
void
-dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_loopmgr_t *loopmgr,
- dns_adb_t **newadb);
+dns_adb_create(isc_mem_t *mem, dns_view_t *view, dns_adb_t **newadb);
/*%<
* Create a new ADB.
*
*
*\li 'view' be a pointer to a valid view.
*
- *\li 'loopmgr' be a valid loop manager.
- *
*\li 'newadb' != NULL && '*newadb' == NULL.
*/
*/
isc_result_t
-dns_view_createresolver(dns_view_t *view, isc_loopmgr_t *loopmgr,
- isc_nm_t *netmgr, unsigned int options,
- isc_tlsctx_cache_t *tlsctx_cache,
+dns_view_createresolver(dns_view_t *view, isc_nm_t *netmgr,
+ unsigned int options, isc_tlsctx_cache_t *tlsctx_cache,
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6);
/*%<
* Create a resolver and address database for the view.
*/
void
-dns_zonemgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *netmgr,
- dns_zonemgr_t **zmgrp);
+dns_zonemgr_create(isc_mem_t *mctx, isc_nm_t *netmgr, dns_zonemgr_t **zmgrp);
/*%<
* Create a zone manager.
*
.magic = NTA_MAGIC,
};
isc_mem_attach(ntatable->mctx, &nta->mctx);
- isc_loop_attach(isc_loop_current(ntatable->loopmgr), &nta->loop);
+ isc_loop_attach(isc_loop(), &nta->loop);
dns_rdataset_init(&nta->rdataset);
dns_rdataset_init(&nta->sigrdataset);
isc_interval_t i;
isc_timer_create(
- isc_loop_current(fctx->res->loopmgr),
- spillattimer_countdown, fctx->res,
- &fctx->res->spillattimer);
+ isc_loop(), spillattimer_countdown,
+ fctx->res, &fctx->res->spillattimer);
isc_interval_set(&i, 20 * 60, 0);
isc_timer_start(fctx->res->spillattimer,
LOCK(&res->primelock);
result = dns_resolver_createfetch(
res, dns_rootname, dns_rdatatype_ns, NULL, NULL, NULL,
- NULL, 0, DNS_FETCHOPT_NOFORWARD, 0, NULL,
- isc_loop_current(res->loopmgr), prime_done, res,
- rdataset, NULL, &res->primefetch);
+ NULL, 0, DNS_FETCHOPT_NOFORWARD, 0, NULL, isc_loop(),
+ prime_done, res, rdataset, NULL, &res->primefetch);
UNLOCK(&res->primelock);
if (result != ISC_R_SUCCESS) {
isc_interval_set(&interval, 0, 0);
}
- rpz->loop = isc_loop_current(rpz->rpzs->loopmgr);
+ rpz->loop = isc_loop();
isc_timer_create(rpz->loop, dns__rpz_timer_cb, rpz, &rpz->updatetimer);
isc_timer_start(rpz->updatetimer, isc_timertype_once, &interval);
}
isc_result_t
-dns_view_createresolver(dns_view_t *view, isc_loopmgr_t *loopmgr,
- isc_nm_t *netmgr, unsigned int options,
- isc_tlsctx_cache_t *tlsctx_cache,
+dns_view_createresolver(dns_view_t *view, isc_nm_t *netmgr,
+ unsigned int options, isc_tlsctx_cache_t *tlsctx_cache,
dns_dispatch_t *dispatchv4,
dns_dispatch_t *dispatchv6) {
isc_result_t result;
isc_mem_t *mctx = NULL;
+ isc_loopmgr_t *loopmgr = isc_loop_getloopmgr(isc_loop());
REQUIRE(DNS_VIEW_VALID(view));
REQUIRE(!view->frozen);
isc_mem_create(&mctx);
isc_mem_setname(mctx, "ADB");
- dns_adb_create(mctx, view, loopmgr, &view->adb);
+ dns_adb_create(mctx, view, &view->adb);
isc_mem_detach(&mctx);
result = dns_requestmgr_create(view->mctx, loopmgr, view->dispatchmgr,
}
void
-dns_zonemgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *netmgr,
- dns_zonemgr_t **zmgrp) {
+dns_zonemgr_create(isc_mem_t *mctx, isc_nm_t *netmgr, dns_zonemgr_t **zmgrp) {
dns_zonemgr_t *zmgr = NULL;
- isc_loop_t *loop = isc_loop_current(loopmgr);
+ isc_loop_t *loop = isc_loop();
+ isc_loopmgr_t *loopmgr = isc_loop_getloopmgr(loop);
REQUIRE(mctx != NULL);
- REQUIRE(loopmgr != NULL);
REQUIRE(netmgr != NULL);
REQUIRE(zmgrp != NULL && *zmgrp == NULL);
ISC_LANG_BEGINDECLS
+/*%<
+ * Returns the current running loop.
+ */
+
+extern thread_local isc_loop_t *isc__loop_local;
+
+static inline isc_loop_t *
+isc_loop(void) {
+ return (isc__loop_local);
+}
void
isc_loopmgr_create(isc_mem_t *mctx, uint32_t nloops, isc_loopmgr_t **loopmgrp);
/*%<
* Private
*/
+thread_local isc_loop_t *isc__loop_local = NULL;
+
static void
ignore_signal(int sig, void (*handler)(int)) {
struct sigaction sa = { .sa_handler = handler };
static void *
loop_thread(void *arg) {
isc_loop_t *loop = (isc_loop_t *)arg;
+ /* Initialize the thread_local variables*/
- /* Initialize the thread_local variable */
+ REQUIRE(isc__loop_local == NULL || isc__loop_local == loop);
+ isc__loop_local = loop;
isc__tid_init(loop->tid);
r = uv_run(&loop->loop, UV_RUN_DEFAULT);
UV_RUNTIME_CHECK(uv_run, r);
+ isc__loop_local = NULL;
+
/* Invalidate the loop early */
loop->magic = 0;
loopmgr = loop->loopmgr;
REQUIRE(VALID_LOOPMGR(loopmgr));
-
- REQUIRE(loop == isc_loop_current(loopmgr));
+ REQUIRE(loop == isc_loop());
timer = isc_mem_get(loop->mctx, sizeof(*timer));
*timer = (isc_timer_t){
}
/* Stop the timer, if the loops are matching */
- if (timer->loop == isc_loop_current(timer->loop->loopmgr)) {
+ if (timer->loop == isc_loop()) {
uv_timer_stop(&timer->timer);
}
}
REQUIRE(VALID_TIMER(timer));
REQUIRE(type == isc_timertype_ticker || type == isc_timertype_once);
- REQUIRE(timer->loop == isc_loop_current(timer->loop->loopmgr));
+ REQUIRE(timer->loop == isc_loop());
loop = timer->loop;
timer = *timerp;
*timerp = NULL;
- REQUIRE(timer->loop == isc_loop_current(timer->loop->loopmgr));
+ REQUIRE(timer->loop == isc_loop());
timer_destroy(timer);
}
static void
first_loop(void *varg) {
struct thread_args *args = varg;
- isc_loop_t *loop = isc_loop_current(args->loopmgr);
+ isc_loop_t *loop = isc_loop();
isc_job_run(loop, &args->job, args->cb, args);
args->worked += stop - start;
args->stop = stop;
if (args->stop - args->start < RUNTIME) {
- isc_job_run(isc_loop_current(args->loopmgr), &args->job,
- args->cb, args);
+ isc_job_run(isc_loop(), &args->job, args->cb, args);
return;
}
isc_async_run(isc_loop_main(args->loopmgr), collect, args);
static void
startup(void *arg) {
isc_loopmgr_t *loopmgr = arg;
- isc_loop_t *loop = isc_loop_current(loopmgr);
+ isc_loop_t *loop = isc_loop();
isc_mem_t *mctx = isc_loop_getmctx(loop);
uint32_t nloops = isc_loopmgr_nloops(loopmgr);
size_t bytes = sizeof(struct bench_state) +
static void
start_ticker(void *varg) {
struct ticker *ticker = varg;
- isc_loop_t *loop = isc_loop_current(ticker->loopmgr);
+ isc_loop_t *loop = isc_loop();
isc_timer_create(loop, tick, NULL, &ticker->timer);
isc_timer_start(ticker->timer, isc_timertype_ticker,
UNUSED(arg);
- dns_zonemgr_create(mctx, loopmgr, netmgr, &myzonemgr);
+ dns_zonemgr_create(mctx, netmgr, &myzonemgr);
dns_zonemgr_shutdown(myzonemgr);
dns_zonemgr_detach(&myzonemgr);
UNUSED(arg);
- dns_zonemgr_create(mctx, loopmgr, netmgr, &myzonemgr);
+ dns_zonemgr_create(mctx, netmgr, &myzonemgr);
result = dns_test_makezone("foo", &zone, NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
UNUSED(arg);
- dns_zonemgr_create(mctx, loopmgr, netmgr, &myzonemgr);
+ dns_zonemgr_create(mctx, netmgr, &myzonemgr);
result = dns_zonemgr_createzone(myzonemgr, &zone);
assert_int_equal(result, ISC_R_SUCCESS);
now = isc_time_now();
- dns_zonemgr_create(mctx, loopmgr, netmgr, &myzonemgr);
+ dns_zonemgr_create(mctx, netmgr, &myzonemgr);
result = dns_test_makezone("foo", &zone, NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
static void
async_multiple(void *arg) {
- isc_loop_t *loop = isc_loop_current(loopmgr);
+ isc_loop_t *loop = isc_loop();
UNUSED(arg);
if (n <= MAX_EXECUTED) {
atomic_fetch_add(&scheduled, 1);
- isc_job_run(isc_loop_current(loopmgr), &ta->job, job_cb, ta);
+ isc_job_run(isc_loop(), &ta->job, job_cb, ta);
} else {
- isc_job_run(isc_loop_current(loopmgr), &ta->job, shutdown_cb,
- ta);
+ isc_job_run(isc_loop(), &ta->job, shutdown_cb, ta);
}
}
*ta = (struct test_arg){ .job = ISC_JOB_INITIALIZER };
}
- isc_job_run(isc_loop_current(loopmgr), &ta->job, job_cb, ta);
+ isc_job_run(isc_loop(), &ta->job, job_cb, ta);
}
ISC_RUN_TEST_IMPL(isc_job_run) {
if (--timer_ticks == 0) {
isc_timer_destroy(&timer);
isc_loopmgr_shutdown(loopmgr);
- timer_stop = isc_loop_now(isc_loop_current(loopmgr));
+ timer_stop = isc_loop_now(isc_loop());
} else {
isc_timer_start(timer, timer_type, &timer_interval);
}
}
ISC_LOOP_SETUP_IMPL(reschedule_up) {
- timer_start = isc_loop_now(isc_loop_current(loopmgr));
+ timer_start = isc_loop_now(isc_loop());
timer_expect = 1;
timer_ticks = 1;
timer_type = isc_timertype_once;
}
ISC_LOOP_SETUP_IMPL(reschedule_down) {
- timer_start = isc_loop_now(isc_loop_current(loopmgr));
+ timer_start = isc_loop_now(isc_loop());
timer_expect = 0;
timer_ticks = 1;
timer_type = isc_timertype_once;
}
ISC_LOOP_SETUP_IMPL(reschedule_from_callback) {
- timer_start = isc_loop_now(isc_loop_current(loopmgr));
+ timer_start = isc_loop_now(isc_loop());
timer_expect = 1;
timer_ticks = 2;
timer_type = isc_timertype_once;
}
ISC_LOOP_SETUP_IMPL(zero) {
- timer_start = isc_loop_now(isc_loop_current(loopmgr));
+ timer_start = isc_loop_now(isc_loop());
timer_expect = 0;
timer_ticks = 1;
timer_type = isc_timertype_once;
}
ISC_LOOP_SETUP_IMPL(reschedule_ticker) {
- timer_start = isc_loop_now(isc_loop_current(loopmgr));
+ timer_start = isc_loop_now(isc_loop());
timer_expect = 1;
timer_ticks = 5;
timer_type = isc_timertype_ticker;
dns_test_setupzonemgr(void) {
REQUIRE(zonemgr == NULL);
- dns_zonemgr_create(mctx, loopmgr, netmgr, &zonemgr);
+ dns_zonemgr_create(mctx, netmgr, &zonemgr);
}
isc_result_t