mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Update lock_blocking code
This commit is contained in:
@@ -6,14 +6,6 @@ pub trait MutexExt<T> {
|
|||||||
|
|
||||||
impl<T> MutexExt<T> for std::sync::Mutex<T> {
|
impl<T> MutexExt<T> for std::sync::Mutex<T> {
|
||||||
fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T> {
|
fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T> {
|
||||||
loop {
|
self.lock().unwrap_or_else(|err| err.into_inner())
|
||||||
match self.try_lock() {
|
|
||||||
Ok(guard) => return guard,
|
|
||||||
Err(std::sync::TryLockError::WouldBlock) => {
|
|
||||||
std::thread::yield_now();
|
|
||||||
}
|
|
||||||
Err(std::sync::TryLockError::Poisoned(err)) => return err.into_inner(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user