1
0
Fork 0
forked from wry/wry

metal: split copy device holder

This commit is contained in:
kossLAN 2026-05-29 21:06:28 -04:00
parent 1e9ed0e568
commit 8c61a3150b
No known key found for this signature in database
2 changed files with 35 additions and 31 deletions

View file

@ -0,0 +1,33 @@
use super::*;
pub struct CopyDeviceHolder {
pub registry: Rc<CopyDeviceRegistry>,
pub devnum: dev_t,
pub dev: OnceCell<Option<Rc<CopyDevice>>>,
}
impl Debug for CopyDeviceHolder {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CopyDeviceHolder").finish_non_exhaustive()
}
}
impl CopyDeviceHolder {
pub fn get(&self) -> Option<Rc<CopyDevice>> {
self.dev
.get_or_init(
|| match self.registry.get(self.devnum)?.create_device().map(Some) {
Ok(d) => d,
Err(e) => {
log::error!(
"Could not get copy device for {}: {}",
self.devnum,
ErrorFmt(e),
);
None
}
},
)
.clone()
}
}