MCPcopy Index your code
hub / github.com/RustPython/RustPython / lock_wrapped

Method lock_wrapped

crates/common/src/lock/thread_mutex.rs:59–67  ·  view source on GitHub ↗

Like `lock()` but wraps the blocking wait in `wrap_fn`. The caller can use this to detach thread state while waiting.

(&self, wrap_fn: F)

Source from the content-addressed store, hash-verified

57 /// Like `lock()` but wraps the blocking wait in `wrap_fn`.
58 /// The caller can use this to detach thread state while waiting.
59 pub fn lock_wrapped<F: FnOnce(&dyn Fn())>(&self, wrap_fn: F) -> bool {
60 let id = self.get_thread_id.nonzero_thread_id().get();
61 if self.owner.load(Ordering::Relaxed) == id {
62 return false;
63 }
64 wrap_fn(&|| self.mutex.lock());
65 self.owner.store(id, Ordering::Relaxed);
66 true
67 }
68
69 /// Returns `Some(true)` if able to successfully lock without blocking, `Some(false)`
70 /// otherwise, and `None` when the mutex is already locked on the current thread.

Callers 2

lockMethod · 0.80
lock_optMethod · 0.80

Calls 6

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

Tested by

no test coverage detected