2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00
Files
bind/lib/isc/trampoline_p.h
Ondřej Surý cbbecfcc82 Add isc_trampoline API to have simple accounting around threads
The current isc_hp API uses internal tid_v variable that gets
incremented for each new thread using hazard pointers.  This tid_v
variable is then used as a index to global shared table with hazard
pointers state.  Since the tid_v is only incremented and never
decremented the table could overflow very quickly if we create set of
threads for short period of time, they finish the work and cease to
exist.  Then we create identical set of threads and so on and so on.
This is not a problem for a normal `named` operation as the set of
threads is stable, but the problematic place are the unit tests where we
test network manager or other APIs (task, timer) that create threads.

This commits adds a thin wrapper around any function called from
isc_thread_create() that adds unique-but-reusable small digit thread id
that can be used as index to f.e. hazard pointer tables.  The trampoline
wrapper ensures that the thread ids will be reused, so the highest
thread_id number doesn't grow indefinitely when threads are created and
destroyed and then created again.  This fixes the hazard pointer table
overflow on machines with many cores. [GL #2396]
2021-02-25 16:21:10 +01:00

54 lines
1.4 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* 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>
typedef struct isc__trampoline isc__trampoline_t;
void
isc__trampoline_initialize(void);
/*%<
* Initialize the thread trampoline internal structures, must be called only
* once as a library constructor (see lib/isc/lib.c).
*/
void
isc__trampoline_shutdown(void);
/*%<
* Destroy the thread trampoline internal structures, must be called only
* once as a library destructor (see lib/isc/lib.c).
*/
isc__trampoline_t *
isc__trampoline_get(isc_threadfunc_t start_routine, isc_threadarg_t arg);
/*%<
* Get a free thread trampoline structure and initialize it with
* start_routine and arg passed to start_routine.
*
* Requires:
*\li 'start_routine' is a valid non-NULL thread start_routine
*/
isc_threadresult_t
isc__trampoline_run(isc_threadarg_t arg);
/*%<
* Run the thread trampoline, this will get passed to the actual
* pthread_create() (or Windows equivalent), initialize the isc_tid_v.
*
* Requires:
*\li 'arg' is a valid isc_trampoline_t
*
* Returns:
*\li return value from start_routine (see isc__trampoline_get())
*/