diff options
author | Vijay Pai <vpai@google.com> | 2018-02-08 13:24:39 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-08 13:24:39 -0800 |
commit | 0024ebc85232333efdbd18899eb6f7bba6b570d8 (patch) | |
tree | 136410619009bf4d8358464dc68ecc6ae04357b0 /include | |
parent | 2a073981f384cc117e7e6b3835888bbf8d30540c (diff) | |
parent | 25b61fd60e9fd24c3b23eac9396e22745f1cf51d (diff) |
Merge pull request #14196 from vjpai/gpr_review_tls
GPR review: Privatize thread-local storage headers
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc/module.modulemap | 4 | ||||
-rw-r--r-- | include/grpc/support/tls.h | 68 | ||||
-rw-r--r-- | include/grpc/support/tls_gcc.h | 50 | ||||
-rw-r--r-- | include/grpc/support/tls_msvc.h | 50 | ||||
-rw-r--r-- | include/grpc/support/tls_pthread.h | 54 |
5 files changed, 0 insertions, 226 deletions
diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index 4f6bf6c9bd..9e1695705c 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -14,7 +14,6 @@ framework module grpc { header "support/sync_generic.h" header "support/thd.h" header "support/time.h" - header "support/tls.h" header "support/useful.h" header "impl/codegen/atm.h" header "impl/codegen/fork.h" @@ -59,9 +58,6 @@ framework module grpc { textual header "support/sync_custom.h" textual header "support/sync_posix.h" textual header "support/sync_windows.h" - textual header "support/tls_gcc.h" - textual header "support/tls_msvc.h" - textual header "support/tls_pthread.h" textual header "impl/codegen/atm_gcc_atomic.h" textual header "impl/codegen/atm_gcc_sync.h" textual header "impl/codegen/atm_windows.h" diff --git a/include/grpc/support/tls.h b/include/grpc/support/tls.h deleted file mode 100644 index 4c9e79b6cf..0000000000 --- a/include/grpc/support/tls.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_SUPPORT_TLS_H -#define GRPC_SUPPORT_TLS_H - -#include <grpc/support/port_platform.h> - -/** Thread local storage. - - A minimal wrapper that should be implementable across many compilers, - and implementable efficiently across most modern compilers. - - Thread locals have type intptr_t. - - Declaring a thread local variable 'foo': - GPR_TLS_DECL(foo); - Thread locals always have static scope. - - Declaring a thread local class variable 'foo': - GPR_TLS_CLASS_DECL(foo); - - Defining the thread local class variable: - GPR_TLS_CLASS_DEF(foo); - - Initializing a thread local (must be done at library initialization - time): - gpr_tls_init(&foo); - - Destroying a thread local: - gpr_tls_destroy(&foo); - - Setting a thread local (returns new_value): - gpr_tls_set(&foo, new_value); - - Accessing a thread local: - current_value = gpr_tls_get(&foo); - - ALL functions here may be implemented as macros. */ - -#ifdef GPR_GCC_TLS -#include <grpc/support/tls_gcc.h> -#endif - -#ifdef GPR_MSVC_TLS -#include <grpc/support/tls_msvc.h> -#endif - -#ifdef GPR_PTHREAD_TLS -#include <grpc/support/tls_pthread.h> -#endif - -#endif /* GRPC_SUPPORT_TLS_H */ diff --git a/include/grpc/support/tls_gcc.h b/include/grpc/support/tls_gcc.h deleted file mode 100644 index b44f0f1c8c..0000000000 --- a/include/grpc/support/tls_gcc.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_SUPPORT_TLS_GCC_H -#define GRPC_SUPPORT_TLS_GCC_H - -#include <stdbool.h> - -#include <grpc/support/log.h> - -/** Thread local storage based on gcc compiler primitives. - #include tls.h to use this - and see that file for documentation */ - -struct gpr_gcc_thread_local { - intptr_t value; -}; - -#define GPR_TLS_DECL(name) \ - static __thread struct gpr_gcc_thread_local name = {0} - -#define GPR_TLS_CLASS_DECL(name) \ - static __thread struct gpr_gcc_thread_local name - -#define GPR_TLS_CLASS_DEF(name) __thread struct gpr_gcc_thread_local name = {0} - -#define gpr_tls_init(tls) \ - do { \ - } while (0) -#define gpr_tls_destroy(tls) \ - do { \ - } while (0) -#define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value)) -#define gpr_tls_get(tls) ((tls)->value) - -#endif /* GRPC_SUPPORT_TLS_GCC_H */ diff --git a/include/grpc/support/tls_msvc.h b/include/grpc/support/tls_msvc.h deleted file mode 100644 index 68a411f5d4..0000000000 --- a/include/grpc/support/tls_msvc.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_SUPPORT_TLS_MSVC_H -#define GRPC_SUPPORT_TLS_MSVC_H - -/** Thread local storage based on ms visual c compiler primitives. - #include tls.h to use this - and see that file for documentation */ - -struct gpr_msvc_thread_local { - intptr_t value; -}; - -/** Use GPR_TLS_DECL to declare tls static variables outside a class */ -#define GPR_TLS_DECL(name) \ - static __declspec(thread) struct gpr_msvc_thread_local name = {0} - -/** Use GPR_TLS_CLASS_DECL to declare tls static variable members of a class. - * GPR_TLS_CLASS_DEF needs to be called to define this member. */ -#define GPR_TLS_CLASS_DECL(name) \ - static __declspec(thread) struct gpr_msvc_thread_local name - -#define GPR_TLS_CLASS_DEF(name) \ - __declspec(thread) struct gpr_msvc_thread_local name = {0} - -#define gpr_tls_init(tls) \ - do { \ - } while (0) -#define gpr_tls_destroy(tls) \ - do { \ - } while (0) -#define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value)) -#define gpr_tls_get(tls) ((tls)->value) - -#endif /* GRPC_SUPPORT_TLS_MSVC_H */ diff --git a/include/grpc/support/tls_pthread.h b/include/grpc/support/tls_pthread.h deleted file mode 100644 index 249c8b16f8..0000000000 --- a/include/grpc/support/tls_pthread.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_SUPPORT_TLS_PTHREAD_H -#define GRPC_SUPPORT_TLS_PTHREAD_H - -#include <grpc/support/log.h> /* for GPR_ASSERT */ -#include <pthread.h> - -/** Thread local storage based on pthread library calls. - #include tls.h to use this - and see that file for documentation */ - -struct gpr_pthread_thread_local { - pthread_key_t key; -}; - -/** Use GPR_TLS_DECL to declare tls static variables outside a class */ -#define GPR_TLS_DECL(name) static struct gpr_pthread_thread_local name = {0} - -/** Use GPR_TLS_CLASS_DECL to declare tls static variable members of a class. - * GPR_TLS_CLASS_DEF needs to be called to define this member. */ -#define GPR_TLS_CLASS_DECL(name) static struct gpr_pthread_thread_local name - -/** Use GPR_TLS_CLASS_DEF to declare tls static variable members of a class. - * GPR_TLS_CLASS_DEF needs to be called to define this member. */ -#define GPR_TLS_CLASS_DEF(name) struct gpr_pthread_thread_local name = {0} - -#define gpr_tls_init(tls) GPR_ASSERT(0 == pthread_key_create(&(tls)->key, NULL)) -#define gpr_tls_destroy(tls) pthread_key_delete((tls)->key) -#define gpr_tls_get(tls) ((intptr_t)pthread_getspecific((tls)->key)) -#ifdef __cplusplus -extern "C" { -#endif -intptr_t gpr_tls_set(struct gpr_pthread_thread_local* tls, intptr_t value); -#ifdef __cplusplus -} -#endif - -#endif /* GRPC_SUPPORT_TLS_PTHREAD_H */ |