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)
| 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. |