3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPC_CORE_LIB_GPR_TLS_H
20 #define GRPC_CORE_LIB_GPR_TLS_H
22 #include <grpc/support/port_platform.h>
24 /** Thread local storage.
26 A minimal wrapper that should be implementable across many compilers,
27 and implementable efficiently across most modern compilers.
29 Thread locals have type intptr_t.
31 Declaring a thread local variable 'foo':
33 Thread locals always have static scope.
35 Declaring a thread local class variable 'foo':
36 GPR_TLS_CLASS_DECL(foo);
38 Defining the thread local class variable:
39 GPR_TLS_CLASS_DEF(foo);
41 Initializing a thread local (must be done at library initialization
45 Destroying a thread local:
46 gpr_tls_destroy(&foo);
48 Setting a thread local (returns new_value):
49 gpr_tls_set(&foo, new_value);
51 Accessing a thread local:
52 current_value = gpr_tls_get(&foo);
54 ALL functions here may be implemented as macros. */
57 #include "src/core/lib/gpr/tls_stdcpp.h"
61 #include "src/core/lib/gpr/tls_gcc.h"
65 #include "src/core/lib/gpr/tls_msvc.h"
68 #ifdef GPR_PTHREAD_TLS
69 #include "src/core/lib/gpr/tls_pthread.h"
72 #endif /* GRPC_CORE_LIB_GPR_TLS_H */