1 /* 2 * 3 * Copyright 2015 gRPC authors. 4 * 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 * 17 */ 18 19 #ifndef GRPC_CORE_LIB_GPR_TLS_H 20 #define GRPC_CORE_LIB_GPR_TLS_H 21 22 #include <grpc/support/port_platform.h> 23 24 /** Thread local storage. 25 26 A minimal wrapper that should be implementable across many compilers, 27 and implementable efficiently across most modern compilers. 28 29 Thread locals have type intptr_t. 30 31 Declaring a thread local variable 'foo': 32 GPR_TLS_DECL(foo); 33 Thread locals always have static scope. 34 35 Declaring a thread local class variable 'foo': 36 GPR_TLS_CLASS_DECL(foo); 37 38 Defining the thread local class variable: 39 GPR_TLS_CLASS_DEF(foo); 40 41 Initializing a thread local (must be done at library initialization 42 time): 43 gpr_tls_init(&foo); 44 45 Destroying a thread local: 46 gpr_tls_destroy(&foo); 47 48 Setting a thread local (returns new_value): 49 gpr_tls_set(&foo, new_value); 50 51 Accessing a thread local: 52 current_value = gpr_tls_get(&foo); 53 54 ALL functions here may be implemented as macros. */ 55 56 #ifdef GPR_GCC_TLS 57 #include "src/core/lib/gpr/tls_gcc.h" 58 #endif 59 60 #ifdef GPR_MSVC_TLS 61 #include "src/core/lib/gpr/tls_msvc.h" 62 #endif 63 64 #ifdef GPR_PTHREAD_TLS 65 #include "src/core/lib/gpr/tls_pthread.h" 66 #endif 67 68 #endif /* GRPC_CORE_LIB_GPR_TLS_H */ 69