58 lines
2.0 KiB
Diff
58 lines
2.0 KiB
Diff
--- a/src/core/util/time.cc
|
|
+++ b/src/core/util/time.cc
|
|
@@ -147,9 +147,13 @@
|
|
|
|
} // namespace
|
|
|
|
-thread_local Timestamp::Source* Timestamp::thread_local_time_source_{
|
|
+thread_local Timestamp::Source* Timestamp::thread_local_time_source_var_{
|
|
NoDestructSingleton<GprNowTimeSource>::Get()};
|
|
|
|
+Timestamp::Source*& Timestamp::thread_local_time_source_() {
|
|
+ return thread_local_time_source_var_;
|
|
+}
|
|
+
|
|
Timestamp ScopedTimeCache::Now() {
|
|
if (!cached_time_.has_value()) {
|
|
previous()->InvalidateCache();
|
|
--- a/src/core/util/time.h
|
|
+++ b/src/core/util/time.h
|
|
@@ -86,15 +86,15 @@
|
|
|
|
class ScopedSource : public Source {
|
|
public:
|
|
- ScopedSource() : previous_(thread_local_time_source_) {
|
|
- thread_local_time_source_ = this;
|
|
+ ScopedSource() : previous_(thread_local_time_source_()) {
|
|
+ thread_local_time_source_() = this;
|
|
}
|
|
ScopedSource(const ScopedSource&) = delete;
|
|
ScopedSource& operator=(const ScopedSource&) = delete;
|
|
void InvalidateCache() override { previous_->InvalidateCache(); }
|
|
|
|
protected:
|
|
- ~ScopedSource() { thread_local_time_source_ = previous_; }
|
|
+ ~ScopedSource() { thread_local_time_source_() = previous_; }
|
|
Source* previous() const { return previous_; }
|
|
|
|
private:
|
|
@@ -110,7 +110,7 @@
|
|
static Timestamp FromCycleCounterRoundUp(gpr_cycle_counter c);
|
|
static Timestamp FromCycleCounterRoundDown(gpr_cycle_counter c);
|
|
|
|
- static Timestamp Now() { return thread_local_time_source_->Now(); }
|
|
+ static Timestamp Now() { return thread_local_time_source_()->Now(); }
|
|
|
|
static constexpr Timestamp FromMillisecondsAfterProcessEpoch(int64_t millis) {
|
|
return Timestamp(millis);
|
|
@@ -163,7 +163,8 @@
|
|
explicit constexpr Timestamp(int64_t millis) : millis_(millis) {}
|
|
|
|
int64_t millis_ = 0;
|
|
- static thread_local Timestamp::Source* thread_local_time_source_;
|
|
+ static Timestamp::Source*& thread_local_time_source_();
|
|
+ static thread_local Timestamp::Source* thread_local_time_source_var_;
|
|
};
|
|
|
|
class ScopedTimeCache final : public Timestamp::ScopedSource {
|