diff options
author | Sree Kuchibhotla <sreek@google.com> | 2017-12-08 10:19:56 -0800 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2017-12-08 10:19:56 -0800 |
commit | ca398ee74a7aed2a45ae58e3c5753c4c99e4d683 (patch) | |
tree | 0e49ba3759a117b66c598158d6ba745178a8ffce /src/core/lib/iomgr/timer_manager.cc | |
parent | 54961bb9e16f84d193077277f7d2d8269f57a411 (diff) | |
parent | 94e676e10f8c739289924b8458a246699e3623ce (diff) |
Merge branch 'master' into cv-wait-monotonic
Diffstat (limited to 'src/core/lib/iomgr/timer_manager.cc')
-rw-r--r-- | src/core/lib/iomgr/timer_manager.cc | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index b68088e4bd..7fb068f10f 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -93,18 +93,17 @@ static void start_timer_thread_and_unlock(void) { // to leak through g_completed_threads and be freed in gc_completed_threads() // before "&ct->t" is written to, causing a use-after-free. gpr_mu_lock(&g_mu); - gpr_thd_new(&ct->t, timer_thread, ct, &opt); + gpr_thd_new(&ct->t, "grpc_global_timer", timer_thread, ct, &opt); gpr_mu_unlock(&g_mu); } void grpc_timer_manager_tick() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_timer_check(&exec_ctx, &next); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_check(&next); } -static void run_some_timers(grpc_exec_ctx* exec_ctx) { +static void run_some_timers() { // if there's something to execute... gpr_mu_lock(&g_mu); // remove a waiter from the pool, and start another thread if necessary @@ -126,7 +125,7 @@ static void run_some_timers(grpc_exec_ctx* exec_ctx) { if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "flush exec_ctx"); } - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); // garbage collect any threads hanging out that are dead gc_completed_threads(); @@ -138,7 +137,7 @@ static void run_some_timers(grpc_exec_ctx* exec_ctx) { // 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_exec_ctx* exec_ctx, grpc_millis next) { +static bool wait_until(grpc_millis next) { gpr_mu_lock(&g_mu); // if we're not threaded anymore, leave if (!g_threaded) { @@ -179,7 +178,7 @@ static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { g_timed_waiter_deadline = next; if (grpc_timer_check_trace.enabled()) { - grpc_millis wait_time = next - grpc_exec_ctx_now(exec_ctx); + grpc_millis wait_time = next - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", wait_time); } @@ -220,15 +219,15 @@ static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { return true; } -static void timer_main_loop(grpc_exec_ctx* exec_ctx) { +static void timer_main_loop() { for (;;) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); // check timer state, updates next to the next time to run a check - switch (grpc_timer_check(exec_ctx, &next)) { + switch (grpc_timer_check(&next)) { case GRPC_TIMERS_FIRED: - run_some_timers(exec_ctx); + run_some_timers(); break; case GRPC_TIMERS_NOT_CHECKED: /* This case only happens under contention, meaning more than one timer @@ -246,7 +245,7 @@ static void timer_main_loop(grpc_exec_ctx* exec_ctx) { next = GRPC_MILLIS_INF_FUTURE; /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: - if (!wait_until(exec_ctx, next)) { + if (!wait_until(next)) { return; } break; @@ -274,10 +273,9 @@ 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_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); + grpc_core::ExecCtx exec_ctx(0); + timer_main_loop(); + timer_thread_cleanup((completed_thread*)completed_thread_ptr); } |