tls macro changes and UV fix

pull/13058/head
Yash Tibrewal 7 years ago
parent eaf67dbdf6
commit ba0689fa2a
  1. 1
      include/grpc/impl/codegen/port_platform.h
  2. 16
      include/grpc/support/tls_gcc.h
  3. 8
      include/grpc/support/tls_msvc.h
  4. 10
      include/grpc/support/tls_pthread.h
  5. 6
      src/core/lib/iomgr/exec_ctx.cc
  6. 14
      src/core/lib/iomgr/exec_ctx.h
  7. 2
      src/core/lib/iomgr/tcp_uv.cc

@ -182,6 +182,7 @@
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#define TLS_NO_SUPPORT 1
#if TARGET_OS_IPHONE
#define GPR_PLATFORM_STRING "ios"
#define GPR_CPU_IPHONE 1

@ -33,12 +33,18 @@ struct gpr_gcc_thread_local {
bool* inited;
};
/** Use GPR_TLS_DECL to declare tls static variables outside a class */
#define GPR_TLS_DECL(name) \
static bool name##_inited = false; \
static __thread struct gpr_gcc_thread_local name = {0, &(name##_inited)}
#define GPR_TLS_NON_STATIC_DECL(name) \
bool name##_inited = false; \
/** 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 bool name##_inited = false; \
static __thread struct gpr_gcc_thread_local name
#define GPR_TLS_CLASS_DEF(name) \
__thread struct gpr_gcc_thread_local name = {0, &(name##_inited)}
#define gpr_tls_init(tls) \
@ -75,8 +81,10 @@ struct gpr_gcc_thread_local {
#define GPR_TLS_DECL(name) \
static __thread struct gpr_gcc_thread_local name = {0}
#define GPR_TLS_NON_STATIC_DECL(name) \
__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 { \

@ -26,10 +26,16 @@ 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}
#define GPR_TLS_NON_STATIC_DECL(name) \
/** 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) \

@ -29,8 +29,16 @@ 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}
#define GPR_TLS_NON_STATIC_DECL(name) 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)

@ -104,13 +104,15 @@ static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable};
grpc_closure_scheduler* grpc_schedule_on_exec_ctx = &exec_ctx_scheduler;
namespace grpc_core {
#ifndef GPR_PTHREAD_TLS
#ifdef TLS_NO_SUPPORT
GPR_TLS_CLASS_DEF(ExecCtx::exec_ctx_);
#else
thread_local ExecCtx* ExecCtx::exec_ctx_ = nullptr;
#endif
void ExecCtx::GlobalInit(void) {
g_start_time = gpr_now(GPR_CLOCK_MONOTONIC);
#ifdef GPR_PTHREAD_TLS
#ifdef TLS_NO_SUPPORT
gpr_tls_init(&exec_ctx_);
#endif
}

@ -171,15 +171,15 @@ on outside context */
/** Global shutdown for ExecCtx. Called by iomgr */
static void GlobalShutdown(void) {
#ifdef GPR_PTHREAD_TLS
#ifdef TLS_NO_SUPPORT
gpr_tls_destroy(&exec_ctx_);
#endif
}
/** Gets pointer to current exec_ctx */
static ExecCtx* Get() {
#ifdef GPR_PTHREAD_TLS
return (ExecCtx*)gpr_tls_get(&exec_ctx_);
#ifdef TLS_NO_SUPPORT
return reinterpret_cast<ExecCtx*>(gpr_tls_get(&exec_ctx_));
#else
return exec_ctx_;
#endif
@ -192,8 +192,8 @@ on outside context */
private:
/** Set exec_ctx_ to exec_ctx */
void Set(ExecCtx* exec_ctx) {
#ifdef GPR_PTHREAD_THS
gpr_tls_set(&exec_ctx_, exec_ctx);
#ifdef TLS_NO_SUPPORT
gpr_tls_set(&exec_ctx_, reinterpret_cast<intptr_t>(exec_ctx));
#else
exec_ctx_ = exec_ctx;
#endif
@ -207,8 +207,8 @@ on outside context */
bool now_is_valid_ = false;
grpc_millis now_ = 0;
#ifdef GPR_PTHREAD_TLS
GPR_TLS_DECL(exec_ctx_);
#ifdef TLS_NO_SUPPORT
GPR_TLS_CLASS_DECL(exec_ctx_);
#else
static thread_local ExecCtx* exec_ctx_;
#endif

@ -145,7 +145,7 @@ static void call_read_cb(grpc_tcp* tcp, grpc_error* error) {
}
tcp->read_slices = NULL;
tcp->read_cb = NULL;
GRPC_CLOSURE_RUN(, cb, error);
GRPC_CLOSURE_RUN(cb, error);
}
static void read_callback(uv_stream_t* stream, ssize_t nread,

Loading…
Cancel
Save