forked from isc-projects/bind9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtid.c
56 lines (47 loc) · 1.13 KB
/
tid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* 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.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <isc/thread.h>
#include <isc/tid.h>
#include <isc/util.h>
/**
* Private
*/
thread_local uint32_t isc__tid_local = ISC_TID_UNKNOWN;
/*
* Zero is a better nonsense value in this case than ISC_TID_UNKNOWN;
* avoids things like trying to allocate 32GB of per-thread counters.
*/
static uint32_t tid_count = 0;
/**
* Protected
*/
void
isc__tid_init(uint32_t tid) {
REQUIRE(isc__tid_local == ISC_TID_UNKNOWN || isc__tid_local == tid);
isc__tid_local = tid;
}
void
isc__tid_initcount(uint32_t count) {
REQUIRE(tid_count == 0 || tid_count == count);
tid_count = count;
}
/**
* Public
*/
uint32_t
isc_tid_count(void) {
return tid_count;
}