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