1 /* $NetBSD: tid.c,v 1.2 2025/01/26 16:25:39 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #include <stdlib.h> 17 #include <sys/types.h> 18 #include <unistd.h> 19 20 #include <isc/lang.h> 21 #include <isc/thread.h> 22 #include <isc/tid.h> 23 #include <isc/util.h> 24 25 /** 26 * Private 27 */ 28 thread_local uint32_t isc__tid_local = ISC_TID_UNKNOWN; 29 30 /* 31 * Zero is a better nonsense value in this case than ISC_TID_UNKNOWN; 32 * avoids things like trying to allocate 32GB of per-thread counters. 33 */ 34 static uint32_t tid_count = 0; 35 36 /** 37 * Protected 38 */ 39 40 void 41 isc__tid_init(uint32_t tid) { 42 REQUIRE(isc__tid_local == ISC_TID_UNKNOWN || isc__tid_local == tid); 43 isc__tid_local = tid; 44 } 45 46 void 47 isc__tid_initcount(uint32_t count) { 48 REQUIRE(tid_count == 0 || tid_count == count); 49 tid_count = count; 50 } 51 52 /** 53 * Public 54 */ 55 56 uint32_t 57 isc_tid_count(void) { 58 return tid_count; 59 } 60