From eaf67dbdf67821b76e67066f201f2fafe1f5859c Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 22 Nov 2017 16:03:32 -0800 Subject: [PATCH] Fixing errors and minor bugs --- src/core/lib/iomgr/exec_ctx.cc | 20 +++++++------------- src/core/lib/iomgr/exec_ctx.h | 20 +++++++++++--------- src/core/lib/iomgr/pollset_uv.cc | 2 +- src/core/lib/iomgr/pollset_windows.cc | 2 +- test/core/util/test_tcp_server.cc | 2 +- test/cpp/microbenchmarks/bm_pollset.cc | 8 ++++---- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 4bd92a41419..25ff686188f 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -108,6 +108,13 @@ namespace grpc_core { thread_local ExecCtx* ExecCtx::exec_ctx_ = nullptr; #endif +void ExecCtx::GlobalInit(void) { + g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); +#ifdef GPR_PTHREAD_TLS + gpr_tls_init(&exec_ctx_); +#endif +} + bool ExecCtx::Flush() { bool did_something = 0; GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); @@ -131,19 +138,6 @@ bool ExecCtx::Flush() { return did_something; } -void ExecCtx::GlobalInit(void) { - g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); -#ifdef GPR_PTHREAD_TLS - gpr_tls_init(&exec_ctx_); -#endif -} - -void ExecCtx::GlobalShutdown(void) { -#ifdef GPR_PTHREAD_TLS - gpr_tls_destroy(&exec_ctx_); -#endif -} - grpc_millis ExecCtx::Now() { if (!now_is_valid_) { now_ = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index 6320e13acb5..6c310a4fd61 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -47,6 +47,12 @@ typedef struct grpc_combiner grpc_combiner; should be given to not delete said call/channel from this exec_ctx */ #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 +extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; + +gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); +grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); +grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); + namespace grpc_core { /** Execution context. * A bag of data that collects information along a callstack. @@ -164,7 +170,11 @@ on outside context */ static void GlobalInit(void); /** Global shutdown for ExecCtx. Called by iomgr */ - static void GlobalShutdown(void); + static void GlobalShutdown(void) { +#ifdef GPR_PTHREAD_TLS + gpr_tls_destroy(&exec_ctx_); +#endif + } /** Gets pointer to current exec_ctx */ static ExecCtx* Get() { @@ -206,14 +216,6 @@ on outside context */ }; } // namespace grpc_core -extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; - -gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); -grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); -grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); - -void grpc_exec_ctx_maybe_update_start_time(); - #ifdef __cplusplus } #endif diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index d040c0cccb6..d9e5ad81be4 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -139,7 +139,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, uv_run(uv_default_loop(), UV_RUN_NOWAIT); } } - if (!grpc_closure_list_empty(exec_ctx->closure_list)) { + if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { grpc_core::ExecCtx::Get()->Flush(); } gpr_mu_lock(&grpc_polling_mu); diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 162037a8da4..6ef949aad70 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -166,7 +166,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, pollset->kicked_without_pollers = 0; } done: - if (!grpc_closure_list_empty(exec_ctx->closure_list)) { + if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { gpr_mu_unlock(&grpc_polling_mu); grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index 71e6f3af2c7..b94297addab 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -106,7 +106,7 @@ void test_tcp_server_destroy(test_tcp_server* server) { grpc_pollset_shutdown(server->pollset, GRPC_CLOSURE_CREATE(finish_pollset, server->pollset, grpc_schedule_on_exec_ctx)); - + grpc_core::ExecCtx::Get()->Flush(); gpr_free(server->pollset); grpc_shutdown(); } diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc index ec0bf4e4b9b..9a859b51eac 100644 --- a/test/cpp/microbenchmarks/bm_pollset.cc +++ b/test/cpp/microbenchmarks/bm_pollset.cc @@ -62,7 +62,7 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { gpr_mu_unlock(mu); grpc_core::ExecCtx::Get()->Flush(); } - + grpc_core::ExecCtx::Get()->Flush(); gpr_free(ps); track_counters.Finish(state); } @@ -124,7 +124,7 @@ static void BM_PollEmptyPollset(benchmark::State& state) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - + grpc_core::ExecCtx::Get()->Flush(); gpr_free(ps); track_counters.Finish(state); } @@ -152,7 +152,7 @@ static void BM_PollAddFd(benchmark::State& state) { gpr_mu_lock(mu); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - + grpc_core::ExecCtx::Get()->Flush(); gpr_free(ps); track_counters.Finish(state); } @@ -248,7 +248,7 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - + grpc_core::ExecCtx::Get()->Flush(); grpc_wakeup_fd_destroy(&wakeup_fd); gpr_free(ps); track_counters.Finish(state);