MCPcopy Create free account
hub / github.com/RustPython/RustPython / lock_internal

Method lock_internal

crates/common/src/lock/thread_mutex.rs:34–45  ·  view source on GitHub ↗
(&self, try_lock: F)

Source from the content-addressed store, hash-verified

32
33 #[inline]
34 fn lock_internal<F: FnOnce() -> bool>(&self, try_lock: F) -> Option<bool> {
35 let id = self.get_thread_id.nonzero_thread_id().get();
36 if self.owner.load(Ordering::Relaxed) == id {
37 return None;
38 } else {
39 if !try_lock() {
40 return Some(false);
41 }
42 self.owner.store(id, Ordering::Relaxed);
43 }
44 Some(true)
45 }
46
47 /// Blocks for the mutex to be available, and returns true if the mutex isn't already
48 /// locked on the current thread.

Callers 2

lockMethod · 0.80
try_lockMethod · 0.80

Calls 5

nonzero_thread_idMethod · 0.80
SomeClass · 0.50
getMethod · 0.45
loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected