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.
| 81 | // lock is returned in the wait_cycles parameter. The last value read |
| 82 | // from the lock is returned from the method. |
| 83 | Atomic32 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 | |
| 97 | void SpinLock::SlowLock() { |
| 98 | // The lock was not obtained initially, so this thread needs to wait for |
nothing calls this directly
no test coverage detected