aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc/support
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-03-17 22:42:39 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2016-03-17 22:42:39 -0700
commit185768b7024504bdb94d3b5448c7ddffc31a5151 (patch)
treed46d1aafaf1c65b673bf038287c26d72b8d6f027 /include/grpc/support
parent3c5def57f65ac92a94f4a78f58fde9ed52aa8e1c (diff)
parentd848db1c06123d23888c705530fc012bcc7e9f35 (diff)
Merge branch 'master' of github.com:grpc/grpc into guard_check
Diffstat (limited to 'include/grpc/support')
-rw-r--r--include/grpc/support/tls_gcc.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/grpc/support/tls_gcc.h b/include/grpc/support/tls_gcc.h
index 2fac5ced95..21269e4b14 100644
--- a/include/grpc/support/tls_gcc.h
+++ b/include/grpc/support/tls_gcc.h
@@ -34,9 +34,51 @@
#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 */
+#ifndef NDEBUG
+
+struct gpr_gcc_thread_local {
+ intptr_t value;
+ bool *inited;
+};
+
+#define GPR_TLS_DECL(name) \
+ static bool name##_inited = false; \
+ static __thread struct gpr_gcc_thread_local name = {0, &(name##_inited)}
+
+#define gpr_tls_init(tls) \
+ do { \
+ GPR_ASSERT(*((tls)->inited) == false); \
+ *((tls)->inited) = true; \
+ } while (0)
+
+/* It is allowed to call gpr_tls_init after gpr_tls_destroy is called. */
+#define gpr_tls_destroy(tls) \
+ do { \
+ GPR_ASSERT(*((tls)->inited)); \
+ *((tls)->inited) = false; \
+ } while (0)
+
+#define gpr_tls_set(tls, new_value) \
+ do { \
+ GPR_ASSERT(*((tls)->inited)); \
+ (tls)->value = (new_value); \
+ } while (0)
+
+#define gpr_tls_get(tls) \
+ ({ \
+ GPR_ASSERT(*((tls)->inited)); \
+ (tls)->value; \
+ })
+
+#else /* NDEBUG */
+
struct gpr_gcc_thread_local {
intptr_t value;
};
@@ -53,4 +95,6 @@ struct gpr_gcc_thread_local {
#define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value))
#define gpr_tls_get(tls) ((tls)->value)
+#endif /* NDEBUG */
+
#endif /* GRPC_SUPPORT_TLS_GCC_H */