diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index ebea7cf6bfe..0079946b4ab 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;