diff options
author | 2016-03-09 12:22:06 -0800 | |
---|---|---|
committer | 2016-03-17 09:49:34 -0700 | |
commit | 5a391064ca04f8864b35b0775c4b4fea5a62ffa4 (patch) | |
tree | 627f4aaf04e3671adce55b6f8d9f7c031f490c38 /include | |
parent | e4ce826e3009bf0de85225fef53fae330e4496ff (diff) |
Add debug support for checking tls_init is called
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc/support/tls_gcc.h | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/include/grpc/support/tls_gcc.h b/include/grpc/support/tls_gcc.h index a697ad05b0..5aebe6ded9 100644 --- a/include/grpc/support/tls_gcc.h +++ b/include/grpc/support/tls_gcc.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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 |