Home | History | Annotate | Line # | Download | only in isc
      1 /*	$NetBSD: tid.c,v 1.3 2026/08/29 14:55:18 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 <sys/types.h>
     17 #include <unistd.h>
     18 
     19 #include <isc/lang.h>
     20 #include <isc/thread.h>
     21 #include <isc/tid.h>
     22 #include <isc/util.h>
     23 
     24 /**
     25  * Private
     26  */
     27 thread_local uint32_t isc__tid_local = ISC_TID_UNKNOWN;
     28 
     29 /*
     30  * Zero is a better nonsense value in this case than ISC_TID_UNKNOWN;
     31  * avoids things like trying to allocate 32GB of per-thread counters.
     32  */
     33 static uint32_t tid_count = 0;
     34 
     35 /**
     36  * Protected
     37  */
     38 
     39 void
     40 isc__tid_init(uint32_t tid) {
     41 	REQUIRE(isc__tid_local == ISC_TID_UNKNOWN || isc__tid_local == tid);
     42 	isc__tid_local = tid;
     43 }
     44 
     45 void
     46 isc__tid_initcount(uint32_t count) {
     47 	REQUIRE(tid_count == 0 || tid_count == count);
     48 	if (tid_count == 0) {
     49 		tid_count = count;
     50 	}
     51 }
     52 
     53 /**
     54  * Public
     55  */
     56 
     57 uint32_t
     58 isc_tid_count(void) {
     59 	return tid_count;
     60 }
     61