MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / background_try_lock

Method background_try_lock

thread/thread.cpp:502–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

500 wait_while(background_locked);
501 }
502 bool background_try_lock() {
503 while(true) {
504 // wait if (unlikely) foreground locked
505 wait_while(foreground_locked);
506
507 // try lock
508 if (background_locked.exchange(true, std::memory_order_acquire))
509 return false; // avoid wait while holding the lock
510
511 // check to make sure it is still unlocked
512 if (likely(!foreground_locked.load(std::memory_order_acquire)))
513 return true;
514
515 // otherwise release lock, wait, and repeat again
516 background_locked.store(false, std::memory_order_release);
517 spin_wait();
518 }
519 return true;
520 }
521 void foreground_unlock() {
522 foreground_locked.store(false, std::memory_order_release);
523 }

Callers 1

ws_scan_runqFunction · 0.80

Calls 3

spin_waitFunction · 0.70
likelyFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected