From 1ac5f4dd2788e7896a566bddd352af013bbdd1b9 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 11 Mar 2020 16:42:28 -0700 Subject: [PATCH] Lazily initialize starting_cpu_ in ExecCtx --- src/core/lib/iomgr/exec_ctx.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index 4e746bc8505..006193d2504 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -21,6 +21,8 @@ #include +#include + #include #include #include @@ -132,7 +134,12 @@ class ExecCtx { ExecCtx(const ExecCtx&) = delete; ExecCtx& operator=(const ExecCtx&) = delete; - unsigned starting_cpu() const { return starting_cpu_; } + unsigned starting_cpu() { + if (starting_cpu_ == std::numeric_limits::max()) { + starting_cpu_ = gpr_cpu_current_cpu(); + } + return starting_cpu_; + } struct CombinerData { /* currently active combiner: updated only via combiner.c */ @@ -239,7 +246,7 @@ class ExecCtx { CombinerData combiner_data_ = {nullptr, nullptr}; uintptr_t flags_; - unsigned starting_cpu_ = gpr_cpu_current_cpu(); + unsigned starting_cpu_ = std::numeric_limits::max(); bool now_is_valid_ = false; grpc_millis now_ = 0;