use a thread-local variable to get the current running loop

if we had a method to get the running loop, similar to how
isc_tid() gets the current thread ID, we can simplify loop
and loopmgr initialization.

remove most uses of isc_loop_current() in favor of isc_loop().
in some places where that was the only reason to pass loopmgr,
remove loopmgr from the function parameters.
This commit is contained in:
Evan Hunt
2024-03-26 00:13:45 -07:00
committed by Ondřej Surý
parent cad6292fc4
commit c47fa689d4
22 changed files with 77 additions and 79 deletions

View File

@@ -207,7 +207,7 @@ struct thread_args {
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);
@@ -222,8 +222,7 @@ next_loop(struct thread_args *args, isc_nanosecs_t start) {
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);
@@ -809,7 +808,7 @@ collect(void *varg) {
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) +
@@ -841,7 +840,7 @@ tick(void *varg) {
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,