diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-12-06 09:05:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 09:05:05 -0800 |
commit | ad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch) | |
tree | 6a657f8c6179d873b34505cdc24bce9462ca68eb /src/core/lib/iomgr/timer_manager.cc | |
parent | a3df36cc2505a89c2f481eea4a66a87b3002844a (diff) |
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'src/core/lib/iomgr/timer_manager.cc')
-rw-r--r-- | src/core/lib/iomgr/timer_manager.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 8ca6a3c23e..87ed0e05dc 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -98,12 +98,13 @@ static void start_timer_thread_and_unlock(void) { } void grpc_timer_manager_tick() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_timer_check(&next); + grpc_timer_check(&exec_ctx, &next); + grpc_exec_ctx_finish(&exec_ctx); } -static void run_some_timers() { +static void run_some_timers(grpc_exec_ctx* exec_ctx) { // if there's something to execute... gpr_mu_lock(&g_mu); // remove a waiter from the pool, and start another thread if necessary @@ -125,7 +126,7 @@ static void run_some_timers() { if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "flush exec_ctx"); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&g_mu); // garbage collect any threads hanging out that are dead gc_completed_threads(); @@ -137,7 +138,7 @@ static void run_some_timers() { // wait until 'next' (or forever if there is already a timed waiter in the pool) // returns true if the thread should continue executing (false if it should // shutdown) -static bool wait_until(grpc_millis next) { +static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { gpr_mu_lock(&g_mu); // if we're not threaded anymore, leave if (!g_threaded) { @@ -178,7 +179,7 @@ static bool wait_until(grpc_millis next) { g_timed_waiter_deadline = next; if (grpc_timer_check_trace.enabled()) { - grpc_millis wait_time = next - grpc_core::ExecCtx::Get()->Now(); + grpc_millis wait_time = next - grpc_exec_ctx_now(exec_ctx); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", wait_time); } @@ -219,15 +220,15 @@ static bool wait_until(grpc_millis next) { return true; } -static void timer_main_loop() { +static void timer_main_loop(grpc_exec_ctx* exec_ctx) { for (;;) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); // check timer state, updates next to the next time to run a check - switch (grpc_timer_check(&next)) { + switch (grpc_timer_check(exec_ctx, &next)) { case GRPC_TIMERS_FIRED: - run_some_timers(); + run_some_timers(exec_ctx); break; case GRPC_TIMERS_NOT_CHECKED: /* This case only happens under contention, meaning more than one timer @@ -245,7 +246,7 @@ static void timer_main_loop() { next = GRPC_MILLIS_INF_FUTURE; /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: - if (!wait_until(next)) { + if (!wait_until(exec_ctx, next)) { return; } break; @@ -273,9 +274,10 @@ static void timer_thread_cleanup(completed_thread* ct) { static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads - grpc_core::ExecCtx exec_ctx(0); - timer_main_loop(); - + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); + timer_main_loop(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); timer_thread_cleanup((completed_thread*)completed_thread_ptr); } |