]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Explicitly create and shutdown the call_rcu_thread
authorOndřej Surý <ondrej@isc.org>
Tue, 4 Feb 2025 18:17:28 +0000 (19:17 +0100)
committerOndřej Surý <ondrej@isc.org>
Sat, 22 Feb 2025 15:19:01 +0000 (16:19 +0100)
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.

lib/isc/Makefile.am
lib/isc/lib.c
lib/isc/thread.c
lib/isc/thread_p.h [new file with mode: 0644]

index 7cdca91b475a011309911b730ba7be4a27430023..4359b517b7ed437b688aac64b952109331928b1b 100644 (file)
@@ -194,6 +194,7 @@ libisc_la_SOURCES =         \
        symtab.c                \
        syslog.c                \
        thread.c                \
+       thread_p.h              \
        tid.c                   \
        time.c                  \
        timer.c                 \
index 4553f4a3b500329b125d5ea350033dbabb8d2229..db3918a5e22bc25b71e7f735e99856a784254108 100644 (file)
@@ -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();
 }
index ca0c1a219a12c3b8c4382579b12f2efabd670db3..8bc0e94ad48b9bb911e7a9106d7123454e1f716c 100644 (file)
 #include <isc/urcu.h>
 #include <isc/util.h>
 
+#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 (file)
index 0000000..6ed32cd
--- /dev/null
@@ -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 <isc/thread.h>
+
+/*! \file */
+
+void
+isc__thread_initialize(void);
+
+void
+isc__thread_shutdown(void);