|
|
|
@ -21,7 +21,6 @@ |
|
|
|
|
#include <inttypes.h> |
|
|
|
|
|
|
|
|
|
#include "absl/log/check.h" |
|
|
|
|
#include "absl/log/log.h" |
|
|
|
|
|
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
@ -90,7 +89,7 @@ static void start_timer_thread_and_unlock(void) { |
|
|
|
|
++g_thread_count; |
|
|
|
|
gpr_mu_unlock(&g_mu); |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "Spawn timer thread"; |
|
|
|
|
gpr_log(GPR_INFO, "Spawn timer thread"); |
|
|
|
|
} |
|
|
|
|
completed_thread* ct = |
|
|
|
|
static_cast<completed_thread*>(gpr_malloc(sizeof(*ct))); |
|
|
|
@ -126,7 +125,7 @@ static void run_some_timers() { |
|
|
|
|
// waiter so that the next deadline is not missed
|
|
|
|
|
if (!g_has_timed_waiter) { |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "kick untimed waiter"; |
|
|
|
|
gpr_log(GPR_INFO, "kick untimed waiter"); |
|
|
|
|
} |
|
|
|
|
gpr_cv_signal(&g_cv_wait); |
|
|
|
|
} |
|
|
|
@ -134,7 +133,7 @@ static void run_some_timers() { |
|
|
|
|
} |
|
|
|
|
// without our lock, flush the exec_ctx
|
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "flush exec_ctx"; |
|
|
|
|
gpr_log(GPR_INFO, "flush exec_ctx"); |
|
|
|
|
} |
|
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
|
gpr_mu_lock(&g_mu); |
|
|
|
@ -200,7 +199,7 @@ static bool wait_until(grpc_core::Timestamp next) { |
|
|
|
|
|
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace) && |
|
|
|
|
next == grpc_core::Timestamp::InfFuture()) { |
|
|
|
|
LOG(INFO) << "sleep until kicked"; |
|
|
|
|
gpr_log(GPR_INFO, "sleep until kicked"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gpr_cv_wait(&g_cv_wait, &g_mu, next.as_timespec(GPR_CLOCK_MONOTONIC)); |
|
|
|
@ -252,7 +251,7 @@ static void timer_main_loop() { |
|
|
|
|
// Consequently, we can just sleep forever here and be happy at some
|
|
|
|
|
// saved wakeup cycles.
|
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "timers not checked: expect another thread to"; |
|
|
|
|
gpr_log(GPR_INFO, "timers not checked: expect another thread to"); |
|
|
|
|
} |
|
|
|
|
next = grpc_core::Timestamp::InfFuture(); |
|
|
|
|
ABSL_FALLTHROUGH_INTENDED; |
|
|
|
@ -278,7 +277,7 @@ static void timer_thread_cleanup(completed_thread* ct) { |
|
|
|
|
g_completed_threads = ct; |
|
|
|
|
gpr_mu_unlock(&g_mu); |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "End timer thread"; |
|
|
|
|
gpr_log(GPR_INFO, "End timer thread"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -319,18 +318,18 @@ void grpc_timer_manager_init(void) { |
|
|
|
|
static void stop_threads(void) { |
|
|
|
|
gpr_mu_lock(&g_mu); |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "stop timer threads: threaded=" << g_threaded; |
|
|
|
|
gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded); |
|
|
|
|
} |
|
|
|
|
if (g_threaded) { |
|
|
|
|
g_threaded = false; |
|
|
|
|
gpr_cv_broadcast(&g_cv_wait); |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "num timer threads: " << g_thread_count; |
|
|
|
|
gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); |
|
|
|
|
} |
|
|
|
|
while (g_thread_count > 0) { |
|
|
|
|
gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) { |
|
|
|
|
LOG(INFO) << "num timer threads: " << g_thread_count; |
|
|
|
|
gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count); |
|
|
|
|
} |
|
|
|
|
gc_completed_threads(); |
|
|
|
|
} |
|
|
|
|