MCPcopy Create free account
hub / github.com/apache/impala / SpinLoop

Method SpinLoop

be/src/gutil/spinlock.cc:83–95  ·  view source on GitHub ↗

Monitor the lock to see if its value changes within some time period (adaptive_spin_count loop iterations). A timestamp indicating when the thread initially started waiting for the lock is passed in via the initial_wait_timestamp value. The total wait time in cycles for the lock is returned in the wait_cycles parameter. The last value read from the lock is returned from the method.

Source from the content-addressed store, hash-verified

81// lock is returned in the wait_cycles parameter. The last value read
82// from the lock is returned from the method.
83Atomic32 SpinLock::SpinLoop(int64 initial_wait_timestamp,
84 Atomic32* wait_cycles) {
85 int c = adaptive_spin_count;
86 while (base::subtle::NoBarrier_Load(&lockword_) != kSpinLockFree && --c > 0) {
87 base::subtle::PauseCPU();
88 }
89 Atomic32 spin_loop_wait_cycles = CalculateWaitCycles(initial_wait_timestamp);
90 Atomic32 lock_value =
91 base::subtle::Acquire_CompareAndSwap(&lockword_, kSpinLockFree,
92 spin_loop_wait_cycles);
93 *wait_cycles = spin_loop_wait_cycles;
94 return lock_value;
95}
96
97void SpinLock::SlowLock() {
98 // The lock was not obtained initially, so this thread needs to wait for

Callers

nothing calls this directly

Calls 3

NoBarrier_LoadFunction · 0.85
PauseCPUFunction · 0.85
Acquire_CompareAndSwapFunction · 0.70

Tested by

no test coverage detected