فهرست منبع

Merge pull request #22314 from yashykt/execctxstartingcpu

Lazily initialize starting_cpu_ in ExecCtx
Yash Tibrewal 5 سال پیش
والد
کامیت
14ab949d98
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      src/core/lib/iomgr/exec_ctx.h

+ 9 - 2
src/core/lib/iomgr/exec_ctx.h

@@ -21,6 +21,8 @@
 
 #include <grpc/support/port_platform.h>
 
+#include <limits>
+
 #include <grpc/impl/codegen/grpc_types.h>
 #include <grpc/support/atm.h>
 #include <grpc/support/cpu.h>
@@ -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<unsigned>::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<unsigned>::max();
 
   bool now_is_valid_ = false;
   grpc_millis now_ = 0;