diff options
author | Muxi Yan <mxyan@google.com> | 2017-11-10 16:50:29 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2017-11-10 16:50:29 -0800 |
commit | 39662f682eb977ce491b3dd52484647f7d48b96b (patch) | |
tree | b2015f1ee03284caf780c3d6060138249b79a90b /src/core | |
parent | f8136e37f21ad3d244332eee4e9c5e537c65f9b6 (diff) |
Add comments
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lib/iomgr/exec_ctx.cc | 9 | ||||
-rw-r--r-- | src/core/lib/iomgr/timer_manager.cc | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index efa344fad1..423e8d059f 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -107,6 +107,10 @@ static void exec_ctx_sched(grpc_exec_ctx* exec_ctx, grpc_closure* closure, grpc_closure_list_append(&exec_ctx->closure_list, closure, error); } +/* This time pair is not entirely thread-safe as store/load of tv_sec and + * tv_nsec are performed separately. However g_start_time do not need to have + * sub-second precision, so it is ok if the value of tv_nsec is off in this + * case. */ typedef struct time_atm_pair { gpr_atm tv_sec; gpr_atm tv_nsec; @@ -208,8 +212,13 @@ void grpc_exec_ctx_maybe_update_start_time(grpc_exec_ctx* exec_ctx) { grpc_millis now = grpc_exec_ctx_now(exec_ctx); grpc_millis last_start_time_update = gpr_atm_no_barrier_load(&g_last_start_time_update); + if (now > last_start_time_update && now - last_start_time_update > GRPC_START_TIME_UPDATE_INTERVAL) { + /* Get the current system time and subtract \a now from it, where \a now is + * the relative time from grpc_init() from monotonic clock. This calibrates + * the time when grpc_exec_ctx_global_init was called based on current + * system clock. */ gpr_atm_no_barrier_store(&g_last_start_time_update, now); gpr_timespec real_now = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec real_start_time = diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 3de87cbf60..bb2a0e0d44 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -226,7 +226,8 @@ static void timer_main_loop(grpc_exec_ctx* exec_ctx) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; grpc_exec_ctx_invalidate_now(exec_ctx); - // Check if it is time to update g_start_time + /* Calibrate g_start_time in exec_ctx.cc with a regular interval in case the + * system clock has changed */ grpc_exec_ctx_maybe_update_start_time(exec_ctx); // check timer state, updates next to the next time to run a check |