use crate::Result;
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
static EXECUTION: RwLock<()> = RwLock::new(());
pub(crate) fn exclusive() -> Result<RwLockWriteGuard<'static, ()>> {
EXECUTION.write().map_err(|_| {
anyhow::anyhow!(
"CUDA capture coordinator poisoned by an earlier panic; restart the process"
)
})
}
pub(crate) fn shared() -> Result<RwLockReadGuard<'static, ()>> {
EXECUTION.read().map_err(|_| {
anyhow::anyhow!(
"CUDA capture coordinator poisoned by an earlier panic; restart the process"
)
})
}
pub(crate) fn teardown() -> RwLockWriteGuard<'static, ()> {
EXECUTION
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner)
}