comparison clang-tools-extra/clangd/support/Threading.cpp @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
comparison
equal deleted inserted replaced
173:0572611fdcc8 207:2e18cbf3894f
114 if (D == Deadline::infinity()) 114 if (D == Deadline::infinity())
115 return CV.wait(Lock); 115 return CV.wait(Lock);
116 CV.wait_until(Lock, D.time()); 116 CV.wait_until(Lock, D.time());
117 } 117 }
118 118
119 bool PeriodicThrottler::operator()() {
120 Rep Now = Stopwatch::now().time_since_epoch().count();
121 Rep OldNext = Next.load(std::memory_order_acquire);
122 if (Now < OldNext)
123 return false;
124 // We're ready to run (but may be racing other threads).
125 // Work out the updated target time, and run if we successfully bump it.
126 Rep NewNext = Now + Period;
127 return Next.compare_exchange_strong(OldNext, NewNext,
128 std::memory_order_acq_rel);
129 }
130
119 } // namespace clangd 131 } // namespace clangd
120 } // namespace clang 132 } // namespace clang