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