changes for macos

pull/13058/head
Yash Tibrewal 7 years ago
parent 177039b2f8
commit d489812215
  1. 11
      src/core/lib/iomgr/exec_ctx.cc
  2. 32
      src/core/lib/iomgr/exec_ctx.h
  3. 18
      test/core/handshake/readahead_handshaker_server_ssl.cc

@ -161,7 +161,9 @@ 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
thread_local ExecCtx* ExecCtx::exec_ctx_ = nullptr;
#endif
bool ExecCtx::Flush() {
bool did_something = 0;
@ -192,9 +194,16 @@ void ExecCtx::GlobalInit(void) {
}
// allows uniform treatment in conversion functions
time_atm_pair_store(&g_start_time[GPR_TIMESPAN], gpr_time_0(GPR_TIMESPAN));
#ifdef GPR_PTHREAD_TLS
gpr_tls_init(&exec_ctx_);
#endif
}
void ExecCtx::GlobalShutdown(void) {}
void ExecCtx::GlobalShutdown(void) {
#ifdef GPR_PTHREAD_TLS
gpr_tls_destroy(&exec_ctx_);
#endif
}
grpc_millis ExecCtx::Now() {
if (!now_is_valid_) {

@ -22,6 +22,7 @@
#include <grpc/support/atm.h>
#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/tls.h>
#include "src/core/lib/iomgr/closure.h"
@ -70,17 +71,17 @@ namespace grpc_core {
class ExecCtx {
public:
/** Default Constructor */
ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { exec_ctx_ = this; }
ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { Set(this); }
/** Parameterised Constructor */
ExecCtx(uintptr_t fl) : flags_(fl) { exec_ctx_ = this; }
ExecCtx(uintptr_t fl) : flags_(fl) { Set(this); }
/** Destructor */
~ExecCtx() {
GPR_ASSERT(exec_ctx_ == this);
GPR_ASSERT(Get() == this);
flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
Flush();
exec_ctx_ = last_exec_ctx_;
Set(last_exec_ctx_);
}
/** Disallow copy and assignment operators */
@ -166,13 +167,28 @@ on outside context */
static void GlobalShutdown(void);
/** Gets pointer to current exec_ctx */
static ExecCtx* Get() { return exec_ctx_; }
static ExecCtx* Get() {
#ifdef GPR_PTHREAD_TLS
return (ExecCtx*)gpr_tls_get(&exec_ctx_);
#else
return exec_ctx_;
#endif
}
protected:
/** Check if ready to finish */
virtual bool CheckReadyToFinish() { return false; }
private:
/** Set exec_ctx_ to exec_ctx */
void Set(ExecCtx* exec_ctx) {
#ifdef GPR_PTHREAD_THS
gpr_tls_set(&exec_ctx_, exec_ctx);
#else
exec_ctx_ = exec_ctx;
#endif
}
grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT;
CombinerData combiner_data_ = {nullptr, nullptr};
uintptr_t flags_;
@ -181,8 +197,12 @@ on outside context */
bool now_is_valid_ = false;
grpc_millis now_ = 0;
#ifdef GPR_PTHREAD_TLS
GPR_TLS_DECL(exec_ctx_);
#else
static thread_local ExecCtx* exec_ctx_;
ExecCtx* last_exec_ctx_ = exec_ctx_;
#endif
ExecCtx* last_exec_ctx_ = Get();
};
} // namespace grpc_core

@ -49,19 +49,16 @@
* to the security_handshaker). This test is meant to protect code relying on
* this functionality that lives outside of this repo. */
static void readahead_handshaker_destroy(
grpc_handshaker* handshaker) {
static void readahead_handshaker_destroy(grpc_handshaker* handshaker) {
gpr_free(handshaker);
}
static void readahead_handshaker_shutdown(
grpc_handshaker* handshaker,
static void readahead_handshaker_shutdown(grpc_handshaker* handshaker,
grpc_error* error) {}
static void readahead_handshaker_do_handshake(
grpc_handshaker* handshaker,
grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done,
grpc_handshaker_args* args) {
grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor,
grpc_closure* on_handshake_done, grpc_handshaker_args* args) {
grpc_endpoint_read(args->endpoint, args->read_buffer, on_handshake_done);
}
@ -76,10 +73,9 @@ static grpc_handshaker* readahead_handshaker_create() {
}
static void readahead_handshaker_factory_add_handshakers(
grpc_handshaker_factory* hf,
const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) {
grpc_handshake_manager_add(handshake_mgr,
readahead_handshaker_create());
grpc_handshaker_factory* hf, const grpc_channel_args* args,
grpc_handshake_manager* handshake_mgr) {
grpc_handshake_manager_add(handshake_mgr, readahead_handshaker_create());
}
static void readahead_handshaker_factory_destroy(

Loading…
Cancel
Save