refactor: split cargo workspace
This commit is contained in:
parent
5db14936e7
commit
1c21bd1259
695 changed files with 32023 additions and 44964 deletions
44
src/backends/metal/video/copy_device.rs
Normal file
44
src/backends/metal/video/copy_device.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use {
|
||||
crate::{
|
||||
copy_device::{CopyDevice, CopyDeviceRegistry},
|
||||
utils::errorfmt::ErrorFmt,
|
||||
},
|
||||
std::{
|
||||
cell::OnceCell,
|
||||
fmt::{Debug, Formatter},
|
||||
rc::Rc,
|
||||
},
|
||||
uapi::c::dev_t,
|
||||
};
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue