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.
This commit is contained in:
Ondřej Surý
2025-02-04 19:17:28 +01:00
parent f5c204ac3e
commit 4917ffa61b
4 changed files with 49 additions and 1 deletions

View File

@@ -194,6 +194,7 @@ libisc_la_SOURCES = \
symtab.c \
syslog.c \
thread.c \
thread_p.h \
tid.c \
time.c \
timer.c \

View 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();
}

View File

@@ -38,10 +38,14 @@
#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);
}

24
lib/isc/thread_p.h Normal file
View File

@@ -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);