From: Ondřej Surý Date: Tue, 4 Feb 2025 18:17:28 +0000 (+0100) Subject: Explicitly create and shutdown the call_rcu_thread X-Git-Tag: ondrej/lock-free-qpzone-reads-v1~36^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4917ffa61b83c4bb453c52516157d1bf0ba4d0d6;p=thirdparty%2Fbind9.git Explicitly create and shutdown the call_rcu_thread As the default_call_rcu_thread can't be forced to flush all the work during the executable shutdown, create one call_rcu_thread explicitly and assign it to the all created threads. This allows this explicit call_rcu_thread to be unassociated from the main thread and freed before the executable destructor exits. --- diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 7cdca91b475..4359b517b7e 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -194,6 +194,7 @@ libisc_la_SOURCES = \ symtab.c \ syslog.c \ thread.c \ + thread_p.h \ tid.c \ time.c \ timer.c \ diff --git a/lib/isc/lib.c b/lib/isc/lib.c index 4553f4a3b50..db3918a5e22 100644 --- a/lib/isc/lib.c +++ b/lib/isc/lib.c @@ -29,6 +29,7 @@ #include "mem_p.h" #include "mutex_p.h" #include "os_p.h" +#include "thread_p.h" /*** *** Functions @@ -48,6 +49,7 @@ isc__lib_initialize(void) { } rcu_register_thread(); + isc__thread_initialize(); isc__os_initialize(); isc__mutex_initialize(); isc__mem_initialize(); @@ -74,6 +76,7 @@ isc__lib_shutdown(void) { isc__mem_shutdown(); isc__mutex_shutdown(); isc__os_shutdown(); + isc__thread_shutdown(); /* should be after isc__mem_shutdown() which calls rcu_barrier() */ rcu_unregister_thread(); } diff --git a/lib/isc/thread.c b/lib/isc/thread.c index ca0c1a219a1..8bc0e94ad48 100644 --- a/lib/isc/thread.c +++ b/lib/isc/thread.c @@ -38,10 +38,14 @@ #include #include +#include "thread_p.h" + #ifndef THREAD_MINSTACKSIZE #define THREAD_MINSTACKSIZE (1024U * 1024) #endif /* ifndef THREAD_MINSTACKSIZE */ +static struct call_rcu_data *isc__thread_call_rcu_data = NULL; + /* * We can't use isc_mem API here, because it's called too early and the * isc_mem_debugging flags can be changed later causing mismatch between flags @@ -97,12 +101,16 @@ thread_run(void *wrap) { rcu_register_thread(); + set_thread_call_rcu_data(isc__thread_call_rcu_data); + void *ret = thread_body(wrap); - isc__iterated_hash_shutdown(); + set_thread_call_rcu_data(NULL); rcu_unregister_thread(); + isc__iterated_hash_shutdown(); + return ret; } @@ -179,3 +187,15 @@ isc_thread_yield(void) { pthread_yield_np(); #endif /* if defined(HAVE_SCHED_YIELD) */ } + +void +isc__thread_initialize(void) { + isc__thread_call_rcu_data = create_call_rcu_data(0, -1); + set_thread_call_rcu_data(isc__thread_call_rcu_data); +} + +void +isc__thread_shutdown(void) { + set_thread_call_rcu_data(NULL); + call_rcu_data_free(isc__thread_call_rcu_data); +} diff --git a/lib/isc/thread_p.h b/lib/isc/thread_p.h new file mode 100644 index 00000000000..6ed32cd984c --- /dev/null +++ b/lib/isc/thread_p.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#pragma once + +#include + +/*! \file */ + +void +isc__thread_initialize(void); + +void +isc__thread_shutdown(void);