29 unsigned int try_count = 0;
30 bool already_locked =
false;
31 while (!locked_.compare_exchange_weak(
32 already_locked,
true, std::memory_order_acquire)) {
33 already_locked =
false;
34 if (++try_count > 1000) {
41 bool already_locked =
false;
42 return locked_.compare_exchange_strong(
43 already_locked,
true, std::memory_order_acquire);
48 locked_.store(
false, std::memory_order_release);
bool TryLock()
Returns true if the mutex was successfully locked, and false otherwise.
void YieldThread()
Causes the calling thread to relinquish the CPU if there are other threads waiting to execute...
bool IsLocked() const
Returns whether the Mutex is currently locked. Does not block.
void Lock()
Locks the Mutex.
Copyright 2016 Google Inc.
void Unlock()
Unlocks the Mutex.