Skip to content

Commit 14ab949

Browse files
authored
Merge pull request grpc#22314 from yashykt/execctxstartingcpu
Lazily initialize starting_cpu_ in ExecCtx
2 parents 29151ef + 1ac5f4d commit 14ab949

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/core/lib/iomgr/exec_ctx.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include <grpc/support/port_platform.h>
2323

24+
#include <limits>
25+
2426
#include <grpc/impl/codegen/grpc_types.h>
2527
#include <grpc/support/atm.h>
2628
#include <grpc/support/cpu.h>
@@ -132,7 +134,12 @@ class ExecCtx {
132134
ExecCtx(const ExecCtx&) = delete;
133135
ExecCtx& operator=(const ExecCtx&) = delete;
134136

135-
unsigned starting_cpu() const { return starting_cpu_; }
137+
unsigned starting_cpu() {
138+
if (starting_cpu_ == std::numeric_limits<unsigned>::max()) {
139+
starting_cpu_ = gpr_cpu_current_cpu();
140+
}
141+
return starting_cpu_;
142+
}
136143

137144
struct CombinerData {
138145
/* currently active combiner: updated only via combiner.c */
@@ -239,7 +246,7 @@ class ExecCtx {
239246
CombinerData combiner_data_ = {nullptr, nullptr};
240247
uintptr_t flags_;
241248

242-
unsigned starting_cpu_ = gpr_cpu_current_cpu();
249+
unsigned starting_cpu_ = std::numeric_limits<unsigned>::max();
243250

244251
bool now_is_valid_ = false;
245252
grpc_millis now_ = 0;

0 commit comments

Comments
 (0)