Add thread pool support for BGI CBG Decoder

This commit is contained in:
2025-09-13 18:44:45 +08:00
parent 8df08f487b
commit e5e437b1e3
10 changed files with 280 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ pub mod atomic;
#[cfg(feature = "fancy-regex")]
pub mod fancy_regex;
pub mod io;
pub mod mutex;
pub mod path;
#[cfg(feature = "emote-psb")]
pub mod psb;

19
src/ext/mutex.rs Normal file
View File

@@ -0,0 +1,19 @@
//! Extension for [std::sync::Mutex].
pub trait MutexExt<T> {
/// Lock the mutex, blocking the current thread until it can be acquired.
fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T>;
}
impl<T> MutexExt<T> for std::sync::Mutex<T> {
fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T> {
loop {
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(),
}
}
}
}