diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lib/iomgr/timer.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/core/lib/iomgr/timer.c b/src/core/lib/iomgr/timer.c index 713f15b69e..c4dfc09c9d 100644 --- a/src/core/lib/iomgr/timer.c +++ b/src/core/lib/iomgr/timer.c @@ -83,6 +83,7 @@ static gpr_timespec compute_min_deadline(shard_type *shard) { void grpc_timer_list_init(gpr_timespec now) { uint32_t i; + g_initialized = true; gpr_mu_init(&g_mu); gpr_mu_init(&g_checker_mu); g_clock_type = now.clock_type; @@ -111,6 +112,7 @@ void grpc_timer_list_shutdown(grpc_exec_ctx *exec_ctx) { } gpr_mu_destroy(&g_mu); gpr_mu_destroy(&g_checker_mu); + g_initialized = false; } /* This is a cheap, but good enough, pointer hash for sharding the tasks: */ @@ -180,6 +182,16 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer, timer->deadline = deadline; timer->triggered = 0; + if (!g_initialized) { + grpc_exec_ctx_enqueue(exec_ctx, &timer->closure, false); + return; + } + + if (gpr_time_cmp(deadline, now) <= 0) { + grpc_exec_ctx_enqueue(exec_ctx, &timer->closure, true); + return; + } + /* TODO(ctiller): check deadline expired */ gpr_mu_lock(&shard->mu); |