all: syncobj is one word
This commit is contained in:
parent
949ff558fd
commit
7a891a6131
20 changed files with 199 additions and 199 deletions
|
|
@ -1,6 +1,6 @@
|
|||
pub mod sync_obj;
|
||||
pub mod syncobj;
|
||||
mod sys;
|
||||
pub mod wait_for_sync_obj;
|
||||
pub mod wait_for_syncobj;
|
||||
pub use consts::*;
|
||||
|
||||
use {
|
||||
|
|
@ -117,27 +117,27 @@ pub enum DrmError {
|
|||
Version(#[source] OsError),
|
||||
#[error("Format of IN_FORMATS property is invalid")]
|
||||
InFormats,
|
||||
#[error("Could not import a sync obj")]
|
||||
ImportSyncObj(#[source] OsError),
|
||||
#[error("Could not create a sync obj")]
|
||||
CreateSyncObj(#[source] OsError),
|
||||
#[error("Could not export a sync obj")]
|
||||
ExportSyncObj(#[source] OsError),
|
||||
#[error("Could not register an eventfd with a sync obj")]
|
||||
#[error("Could not import a syncobj")]
|
||||
ImportSyncobj(#[source] OsError),
|
||||
#[error("Could not create a syncobj")]
|
||||
CreateSyncobj(#[source] OsError),
|
||||
#[error("Could not export a syncobj")]
|
||||
ExportSyncobj(#[source] OsError),
|
||||
#[error("Could not register an eventfd with a syncobj")]
|
||||
RegisterEventfd(#[source] OsError),
|
||||
#[error("Could not create an eventfd")]
|
||||
EventFd(#[source] OsError),
|
||||
#[error("Could not read from an eventfd")]
|
||||
ReadEventFd(#[source] IoUringError),
|
||||
#[error("No sync obj context available")]
|
||||
NoSyncObjContextAvailable,
|
||||
#[error("Could not signal the sync obj")]
|
||||
SignalSyncObj(#[source] OsError),
|
||||
#[error("Could not transfer a sync obj point")]
|
||||
#[error("No syncobj context available")]
|
||||
NoSyncobjContextAvailable,
|
||||
#[error("Could not signal the syncobj")]
|
||||
SignalSyncobj(#[source] OsError),
|
||||
#[error("Could not transfer a syncobj point")]
|
||||
TransferPoint(#[source] OsError),
|
||||
#[error("Could not merge two sync files")]
|
||||
Merge(#[source] OsError),
|
||||
#[error("Could not import a sync file into a sync obj")]
|
||||
#[error("Could not import a sync file into a syncobj")]
|
||||
ImportSyncFile(#[source] OsError),
|
||||
#[error("Could not create a lease")]
|
||||
CreateLease(#[source] OsError),
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ use {
|
|||
DRM_SYNCOBJ_CREATE_SIGNALED, DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE,
|
||||
DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE,
|
||||
DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE,
|
||||
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE, sync_ioc_merge, sync_obj_create,
|
||||
sync_obj_destroy, sync_obj_eventfd, sync_obj_fd_to_handle, sync_obj_handle_to_fd,
|
||||
sync_obj_signal, sync_obj_transfer,
|
||||
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE, sync_ioc_merge, syncobj_create,
|
||||
syncobj_destroy, syncobj_eventfd, syncobj_fd_to_handle, syncobj_handle_to_fd,
|
||||
syncobj_signal, syncobj_transfer,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -32,26 +32,26 @@ use {
|
|||
static SYNCOBJ_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct SyncObjId(u64);
|
||||
pub struct SyncobjId(u64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
struct SyncObjHandle(u32);
|
||||
struct SyncobjHandle(u32);
|
||||
|
||||
unsafe impl UnsafeCellCloneSafe for SyncObjHandle {}
|
||||
unsafe impl UnsafeCellCloneSafe for SyncobjHandle {}
|
||||
|
||||
pub struct SyncObj {
|
||||
id: SyncObjId,
|
||||
pub struct Syncobj {
|
||||
id: SyncobjId,
|
||||
fd: Rc<OwnedFd>,
|
||||
importers: LinkedList<Rc<Handles>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub struct SyncObjPoint(pub u64);
|
||||
pub struct SyncobjPoint(pub u64);
|
||||
|
||||
impl SyncObj {
|
||||
impl Syncobj {
|
||||
pub fn new(fd: &Rc<OwnedFd>) -> Self {
|
||||
Self {
|
||||
id: SyncObjId(SYNCOBJ_ID.fetch_add(1, Relaxed)),
|
||||
id: SyncobjId(SYNCOBJ_ID.fetch_add(1, Relaxed)),
|
||||
fd: fd.clone(),
|
||||
importers: Default::default(),
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ impl SyncObj {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for SyncObj {
|
||||
impl Drop for Syncobj {
|
||||
fn drop(&mut self) {
|
||||
let mut links = vec![];
|
||||
for importer in self.importers.iter() {
|
||||
|
|
@ -79,17 +79,17 @@ impl Drop for SyncObj {
|
|||
|
||||
struct Handles {
|
||||
drm: Rc<OwnedFd>,
|
||||
handles: CopyHashMap<SyncObjId, SyncObjHandle>,
|
||||
links: CopyHashMap<SyncObjId, LinkedNode<Rc<Handles>>>,
|
||||
handles: CopyHashMap<SyncobjId, SyncobjHandle>,
|
||||
links: CopyHashMap<SyncobjId, LinkedNode<Rc<Handles>>>,
|
||||
}
|
||||
|
||||
pub struct SyncObjCtx {
|
||||
pub struct SyncobjCtx {
|
||||
inner: Rc<Handles>,
|
||||
dummy: CloneCell<Option<Rc<SyncObj>>>,
|
||||
dummy: CloneCell<Option<Rc<Syncobj>>>,
|
||||
supports_timeline_import: OnceCell<bool>,
|
||||
}
|
||||
|
||||
impl SyncObjCtx {
|
||||
impl SyncobjCtx {
|
||||
pub fn new(drm: &Rc<OwnedFd>) -> Self {
|
||||
Self {
|
||||
inner: Rc::new(Handles {
|
||||
|
|
@ -102,45 +102,45 @@ impl SyncObjCtx {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_handle(&self, sync_obj: &SyncObj) -> Result<SyncObjHandle, DrmError> {
|
||||
if let Some(handle) = self.inner.handles.get(&sync_obj.id) {
|
||||
fn get_handle(&self, syncobj: &Syncobj) -> Result<SyncobjHandle, DrmError> {
|
||||
if let Some(handle) = self.inner.handles.get(&syncobj.id) {
|
||||
return Ok(handle);
|
||||
}
|
||||
let handle = sync_obj_fd_to_handle(self.inner.drm.raw(), sync_obj.fd.raw(), 0, 0, 0)
|
||||
.map_err(DrmError::ImportSyncObj)?;
|
||||
let handle = SyncObjHandle(handle);
|
||||
let link = sync_obj.importers.add_last(self.inner.clone());
|
||||
self.inner.handles.set(sync_obj.id, handle);
|
||||
self.inner.links.set(sync_obj.id, link);
|
||||
let handle = syncobj_fd_to_handle(self.inner.drm.raw(), syncobj.fd.raw(), 0, 0, 0)
|
||||
.map_err(DrmError::ImportSyncobj)?;
|
||||
let handle = SyncobjHandle(handle);
|
||||
let link = syncobj.importers.add_last(self.inner.clone());
|
||||
self.inner.handles.set(syncobj.id, handle);
|
||||
self.inner.links.set(syncobj.id, link);
|
||||
Ok(handle)
|
||||
}
|
||||
|
||||
pub fn create_sync_obj(&self) -> Result<SyncObj, DrmError> {
|
||||
let handle = sync_obj_create(self.inner.drm.raw(), 0).map_err(DrmError::CreateSyncObj)?;
|
||||
let handle = SyncObjHandle(handle);
|
||||
let fd = sync_obj_handle_to_fd(self.inner.drm.raw(), handle.0, 0);
|
||||
pub fn create_syncobj(&self) -> Result<Syncobj, DrmError> {
|
||||
let handle = syncobj_create(self.inner.drm.raw(), 0).map_err(DrmError::CreateSyncobj)?;
|
||||
let handle = SyncobjHandle(handle);
|
||||
let fd = syncobj_handle_to_fd(self.inner.drm.raw(), handle.0, 0);
|
||||
if fd.is_err() {
|
||||
destroy(&self.inner.drm, handle);
|
||||
}
|
||||
let fd = fd.map_err(DrmError::ExportSyncObj).map(Rc::new)?;
|
||||
let sync_obj = SyncObj::new(&fd);
|
||||
let link = sync_obj.importers.add_last(self.inner.clone());
|
||||
self.inner.handles.set(sync_obj.id, handle);
|
||||
self.inner.links.set(sync_obj.id, link);
|
||||
Ok(sync_obj)
|
||||
let fd = fd.map_err(DrmError::ExportSyncobj).map(Rc::new)?;
|
||||
let syncobj = Syncobj::new(&fd);
|
||||
let link = syncobj.importers.add_last(self.inner.clone());
|
||||
self.inner.handles.set(syncobj.id, handle);
|
||||
self.inner.links.set(syncobj.id, link);
|
||||
Ok(syncobj)
|
||||
}
|
||||
|
||||
pub fn create_signaled_sync_file(&self) -> Result<SyncFile, DrmError> {
|
||||
let handle = sync_obj_create(self.inner.drm.raw(), DRM_SYNCOBJ_CREATE_SIGNALED)
|
||||
.map_err(DrmError::CreateSyncObj)?;
|
||||
let handle = SyncObjHandle(handle);
|
||||
let fd = sync_obj_handle_to_fd(
|
||||
let handle = syncobj_create(self.inner.drm.raw(), DRM_SYNCOBJ_CREATE_SIGNALED)
|
||||
.map_err(DrmError::CreateSyncobj)?;
|
||||
let handle = SyncobjHandle(handle);
|
||||
let fd = syncobj_handle_to_fd(
|
||||
self.inner.drm.raw(),
|
||||
handle.0,
|
||||
DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE,
|
||||
);
|
||||
destroy(&self.inner.drm, handle);
|
||||
fd.map_err(DrmError::ExportSyncObj)
|
||||
fd.map_err(DrmError::ExportSyncobj)
|
||||
.map(Rc::new)
|
||||
.map(SyncFile)
|
||||
}
|
||||
|
|
@ -148,16 +148,16 @@ impl SyncObjCtx {
|
|||
pub fn wait_for_point(
|
||||
&self,
|
||||
eventfd: &OwnedFd,
|
||||
sync_obj: &SyncObj,
|
||||
point: SyncObjPoint,
|
||||
syncobj: &Syncobj,
|
||||
point: SyncobjPoint,
|
||||
signaled: bool,
|
||||
) -> Result<(), DrmError> {
|
||||
let handle = self.get_handle(sync_obj)?;
|
||||
let handle = self.get_handle(syncobj)?;
|
||||
let flags = match signaled {
|
||||
true => 0,
|
||||
false => DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE,
|
||||
};
|
||||
sync_obj_eventfd(
|
||||
syncobj_eventfd(
|
||||
self.inner.drm.raw(),
|
||||
eventfd.raw(),
|
||||
handle.0,
|
||||
|
|
@ -172,11 +172,11 @@ impl SyncObjCtx {
|
|||
}
|
||||
|
||||
fn supports_async_wait_(&self) -> Result<(), DrmError> {
|
||||
let sync_obj = self.create_sync_obj()?;
|
||||
let syncobj = self.create_syncobj()?;
|
||||
let eventfd = uapi::eventfd(0, c::EFD_CLOEXEC)
|
||||
.map_err(OsError::from)
|
||||
.map_err(DrmError::EventFd)?;
|
||||
self.wait_for_point(&eventfd, &sync_obj, SyncObjPoint(1), true)?;
|
||||
self.wait_for_point(&eventfd, &syncobj, SyncobjPoint(1), true)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -199,40 +199,40 @@ impl SyncObjCtx {
|
|||
}
|
||||
|
||||
fn test_timeline_import(&self) -> Result<(), DrmError> {
|
||||
let sync_obj = self.create_sync_obj()?;
|
||||
let sync_obj = self.get_handle(&sync_obj)?;
|
||||
let syncobj = self.create_syncobj()?;
|
||||
let syncobj = self.get_handle(&syncobj)?;
|
||||
let sync_file = self.create_signaled_sync_file()?;
|
||||
sync_obj_fd_to_handle(
|
||||
syncobj_fd_to_handle(
|
||||
self.inner.drm.raw(),
|
||||
sync_file.raw(),
|
||||
DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
|
||||
| DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE,
|
||||
sync_obj.0,
|
||||
syncobj.0,
|
||||
123,
|
||||
)
|
||||
.map(drop)
|
||||
.map_err(DrmError::ImportSyncFile)
|
||||
}
|
||||
|
||||
pub fn signal(&self, sync_obj: &SyncObj, point: SyncObjPoint) -> Result<(), DrmError> {
|
||||
let handle = self.get_handle(sync_obj)?;
|
||||
sync_obj_signal(self.inner.drm.raw(), handle.0, point.0).map_err(DrmError::SignalSyncObj)
|
||||
pub fn signal(&self, syncobj: &Syncobj, point: SyncobjPoint) -> Result<(), DrmError> {
|
||||
let handle = self.get_handle(syncobj)?;
|
||||
syncobj_signal(self.inner.drm.raw(), handle.0, point.0).map_err(DrmError::SignalSyncobj)
|
||||
}
|
||||
|
||||
pub fn import_sync_files<'a, I>(
|
||||
&self,
|
||||
sync_obj: &SyncObj,
|
||||
point: SyncObjPoint,
|
||||
syncobj: &Syncobj,
|
||||
point: SyncobjPoint,
|
||||
sync_files: I,
|
||||
) -> Result<(), DrmError>
|
||||
where
|
||||
I: IntoIterator<Item = &'a SyncFile>,
|
||||
{
|
||||
let Some(fd) = merge_sync_files(sync_files)? else {
|
||||
return self.signal(sync_obj, point);
|
||||
return self.signal(syncobj, point);
|
||||
};
|
||||
let import = |flags: u32, handle: SyncObjHandle| {
|
||||
sync_obj_fd_to_handle(
|
||||
let import = |flags: u32, handle: SyncobjHandle| {
|
||||
syncobj_fd_to_handle(
|
||||
self.inner.drm.raw(),
|
||||
fd.raw(),
|
||||
DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE | flags,
|
||||
|
|
@ -245,24 +245,24 @@ impl SyncObjCtx {
|
|||
if self.supports_timeline_import() {
|
||||
return import(
|
||||
DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE,
|
||||
self.get_handle(sync_obj)?,
|
||||
self.get_handle(syncobj)?,
|
||||
);
|
||||
}
|
||||
let dummy = self.get_dummy()?;
|
||||
import(0, self.get_handle(&dummy)?)?;
|
||||
self.transfer(&dummy, SyncObjPoint(0), sync_obj, point)
|
||||
self.transfer(&dummy, SyncobjPoint(0), syncobj, point)
|
||||
}
|
||||
|
||||
fn transfer(
|
||||
&self,
|
||||
src_sync_obj: &SyncObj,
|
||||
src_point: SyncObjPoint,
|
||||
dst_sync_obj: &SyncObj,
|
||||
dst_point: SyncObjPoint,
|
||||
src_syncobj: &Syncobj,
|
||||
src_point: SyncobjPoint,
|
||||
dst_syncobj: &Syncobj,
|
||||
dst_point: SyncobjPoint,
|
||||
) -> Result<(), DrmError> {
|
||||
let src_handle = self.get_handle(src_sync_obj)?;
|
||||
let dst_handle = self.get_handle(dst_sync_obj)?;
|
||||
sync_obj_transfer(
|
||||
let src_handle = self.get_handle(src_syncobj)?;
|
||||
let dst_handle = self.get_handle(dst_syncobj)?;
|
||||
syncobj_transfer(
|
||||
self.inner.drm.raw(),
|
||||
src_handle.0,
|
||||
src_point.0,
|
||||
|
|
@ -273,11 +273,11 @@ impl SyncObjCtx {
|
|||
.map_err(DrmError::TransferPoint)
|
||||
}
|
||||
|
||||
fn get_dummy(&self) -> Result<Rc<SyncObj>, DrmError> {
|
||||
fn get_dummy(&self) -> Result<Rc<Syncobj>, DrmError> {
|
||||
match self.dummy.get() {
|
||||
Some(d) => Ok(d),
|
||||
None => {
|
||||
let d = Rc::new(self.create_sync_obj()?);
|
||||
let d = Rc::new(self.create_syncobj()?);
|
||||
self.dummy.set(Some(d.clone()));
|
||||
Ok(d)
|
||||
}
|
||||
|
|
@ -285,7 +285,7 @@ impl SyncObjCtx {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for SyncObjCtx {
|
||||
impl Drop for SyncobjCtx {
|
||||
fn drop(&mut self) {
|
||||
self.inner.links.clear();
|
||||
let mut map = self.inner.handles.lock();
|
||||
|
|
@ -295,9 +295,9 @@ impl Drop for SyncObjCtx {
|
|||
}
|
||||
}
|
||||
|
||||
fn destroy(drm: &OwnedFd, handle: SyncObjHandle) {
|
||||
if let Err(e) = sync_obj_destroy(drm.raw(), handle.0) {
|
||||
log::error!("Could not destroy sync obj: {}", ErrorFmt(e));
|
||||
fn destroy(drm: &OwnedFd, handle: SyncobjHandle) {
|
||||
if let Err(e) = syncobj_destroy(drm.raw(), handle.0) {
|
||||
log::error!("Could not destroy syncobj: {}", ErrorFmt(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1195,7 +1195,7 @@ struct drm_syncobj_create {
|
|||
|
||||
const DRM_IOCTL_SYNCOBJ_CREATE: u64 = drm_iowr::<drm_syncobj_create>(0xBF);
|
||||
|
||||
pub fn sync_obj_create(drm: c::c_int, flags: u32) -> Result<u32, OsError> {
|
||||
pub fn syncobj_create(drm: c::c_int, flags: u32) -> Result<u32, OsError> {
|
||||
let mut res = drm_syncobj_create { handle: 0, flags };
|
||||
unsafe {
|
||||
ioctl(drm, DRM_IOCTL_SYNCOBJ_CREATE, &mut res)?;
|
||||
|
|
@ -1211,7 +1211,7 @@ struct drm_syncobj_destroy {
|
|||
|
||||
const DRM_IOCTL_SYNCOBJ_DESTROY: u64 = drm_iowr::<drm_syncobj_destroy>(0xC0);
|
||||
|
||||
pub fn sync_obj_destroy(drm: c::c_int, handle: u32) -> Result<(), OsError> {
|
||||
pub fn syncobj_destroy(drm: c::c_int, handle: u32) -> Result<(), OsError> {
|
||||
let mut res = drm_syncobj_destroy { handle, pad: 0 };
|
||||
unsafe {
|
||||
ioctl(drm, DRM_IOCTL_SYNCOBJ_DESTROY, &mut res)?;
|
||||
|
|
@ -1236,7 +1236,7 @@ struct drm_syncobj_handle {
|
|||
const DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD: u64 = drm_iowr::<drm_syncobj_handle>(0xC1);
|
||||
const DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE: u64 = drm_iowr::<drm_syncobj_handle>(0xC2);
|
||||
|
||||
pub fn sync_obj_handle_to_fd(drm: c::c_int, handle: u32, flags: u32) -> Result<OwnedFd, OsError> {
|
||||
pub fn syncobj_handle_to_fd(drm: c::c_int, handle: u32, flags: u32) -> Result<OwnedFd, OsError> {
|
||||
let mut res = drm_syncobj_handle {
|
||||
handle,
|
||||
flags,
|
||||
|
|
@ -1250,7 +1250,7 @@ pub fn sync_obj_handle_to_fd(drm: c::c_int, handle: u32, flags: u32) -> Result<O
|
|||
Ok(OwnedFd::new(res.fd))
|
||||
}
|
||||
|
||||
pub fn sync_obj_fd_to_handle(
|
||||
pub fn syncobj_fd_to_handle(
|
||||
drm: c::c_int,
|
||||
fd: c::c_int,
|
||||
flags: u32,
|
||||
|
|
@ -1285,7 +1285,7 @@ struct drm_syncobj_eventfd {
|
|||
|
||||
const DRM_IOCTL_SYNCOBJ_EVENTFD: u64 = drm_iowr::<drm_syncobj_eventfd>(0xCF);
|
||||
|
||||
pub fn sync_obj_eventfd(
|
||||
pub fn syncobj_eventfd(
|
||||
drm: c::c_int,
|
||||
eventfd: c::c_int,
|
||||
handle: u32,
|
||||
|
|
@ -1315,7 +1315,7 @@ struct drm_syncobj_timeline_array {
|
|||
|
||||
const DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL: u64 = drm_iowr::<drm_syncobj_timeline_array>(0xCD);
|
||||
|
||||
pub fn sync_obj_signal(drm: c::c_int, handle: u32, point: u64) -> Result<(), OsError> {
|
||||
pub fn syncobj_signal(drm: c::c_int, handle: u32, point: u64) -> Result<(), OsError> {
|
||||
let mut res = drm_syncobj_timeline_array {
|
||||
handles: &handle as *const u32 as u64,
|
||||
points: &point as *const u64 as u64,
|
||||
|
|
@ -1340,7 +1340,7 @@ struct drm_syncobj_transfer {
|
|||
|
||||
const DRM_IOCTL_SYNCOBJ_TRANSFER: u64 = drm_iowr::<drm_syncobj_transfer>(0xCC);
|
||||
|
||||
pub fn sync_obj_transfer(
|
||||
pub fn syncobj_transfer(
|
||||
drm: c::c_int,
|
||||
src_handle: u32,
|
||||
src_point: u64,
|
||||
|
|
|
|||
|
|
@ -8,19 +8,19 @@ use {
|
|||
},
|
||||
video::drm::{
|
||||
DrmError,
|
||||
sync_obj::{SyncObj, SyncObjCtx, SyncObjPoint},
|
||||
syncobj::{Syncobj, SyncobjCtx, SyncobjPoint},
|
||||
},
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
uapi::{OwnedFd, c},
|
||||
};
|
||||
|
||||
pub struct WaitForSyncObj {
|
||||
pub struct WaitForSyncobj {
|
||||
inner: Rc<Inner>,
|
||||
eng: Rc<AsyncEngine>,
|
||||
}
|
||||
|
||||
pub trait SyncObjWaiter {
|
||||
pub trait SyncobjWaiter {
|
||||
fn done(self: Rc<Self>, result: Result<(), DrmError>);
|
||||
}
|
||||
|
||||
|
|
@ -28,13 +28,13 @@ pub trait SyncObjWaiter {
|
|||
struct JobId(u64);
|
||||
|
||||
#[must_use]
|
||||
pub struct WaitForSyncObjHandle {
|
||||
pub struct WaitForSyncobjHandle {
|
||||
inner: Rc<Inner>,
|
||||
id: JobId,
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
ctx: CloneCell<Option<Rc<SyncObjCtx>>>,
|
||||
ctx: CloneCell<Option<Rc<SyncobjCtx>>>,
|
||||
next_id: NumCell<u64>,
|
||||
ring: Rc<IoUring>,
|
||||
busy: CopyHashMap<JobId, BusyWaiter>,
|
||||
|
|
@ -44,7 +44,7 @@ struct Inner {
|
|||
struct BusyWaiter {
|
||||
waiter: Waiter,
|
||||
job: Job,
|
||||
sow: Rc<dyn SyncObjWaiter>,
|
||||
sow: Rc<dyn SyncobjWaiter>,
|
||||
}
|
||||
|
||||
struct Waiter {
|
||||
|
|
@ -55,8 +55,8 @@ struct Waiter {
|
|||
#[derive(Clone)]
|
||||
struct Job {
|
||||
id: JobId,
|
||||
sync_obj: Rc<SyncObj>,
|
||||
point: SyncObjPoint,
|
||||
syncobj: Rc<Syncobj>,
|
||||
point: SyncobjPoint,
|
||||
signaled: bool,
|
||||
}
|
||||
|
||||
|
|
@ -67,13 +67,13 @@ struct WaiterInner {
|
|||
trigger: AsyncEvent,
|
||||
}
|
||||
|
||||
impl Drop for WaitForSyncObjHandle {
|
||||
impl Drop for WaitForSyncobjHandle {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.inner.busy.remove(&self.id);
|
||||
}
|
||||
}
|
||||
|
||||
impl WaitForSyncObj {
|
||||
impl WaitForSyncobj {
|
||||
pub fn new(ring: &Rc<IoUring>, eng: &Rc<AsyncEngine>) -> Self {
|
||||
Self {
|
||||
inner: Rc::new(Inner {
|
||||
|
|
@ -93,13 +93,13 @@ impl WaitForSyncObj {
|
|||
self.inner.idle.take();
|
||||
}
|
||||
|
||||
pub fn set_ctx(&self, ctx: Option<Rc<SyncObjCtx>>) {
|
||||
pub fn set_ctx(&self, ctx: Option<Rc<SyncobjCtx>>) {
|
||||
self.inner.ctx.set(ctx);
|
||||
let busy_waiters: Vec<_> = self.inner.busy.lock().drain_values().collect();
|
||||
for waiter in busy_waiters {
|
||||
let res = self.submit_job(
|
||||
waiter.job.id,
|
||||
&waiter.job.sync_obj,
|
||||
&waiter.job.syncobj,
|
||||
waiter.job.point,
|
||||
waiter.job.signaled,
|
||||
waiter.sow.clone(),
|
||||
|
|
@ -112,14 +112,14 @@ impl WaitForSyncObj {
|
|||
|
||||
pub fn wait(
|
||||
&self,
|
||||
sync_obj: &Rc<SyncObj>,
|
||||
point: SyncObjPoint,
|
||||
syncobj: &Rc<Syncobj>,
|
||||
point: SyncobjPoint,
|
||||
signaled: bool,
|
||||
sow: Rc<dyn SyncObjWaiter>,
|
||||
) -> Result<WaitForSyncObjHandle, DrmError> {
|
||||
sow: Rc<dyn SyncobjWaiter>,
|
||||
) -> Result<WaitForSyncobjHandle, DrmError> {
|
||||
let job_id = JobId(self.inner.next_id.fetch_add(1));
|
||||
self.submit_job(job_id, sync_obj, point, signaled, sow)?;
|
||||
Ok(WaitForSyncObjHandle {
|
||||
self.submit_job(job_id, syncobj, point, signaled, sow)?;
|
||||
Ok(WaitForSyncobjHandle {
|
||||
inner: self.inner.clone(),
|
||||
id: job_id,
|
||||
})
|
||||
|
|
@ -128,10 +128,10 @@ impl WaitForSyncObj {
|
|||
fn submit_job(
|
||||
&self,
|
||||
job_id: JobId,
|
||||
sync_obj: &Rc<SyncObj>,
|
||||
point: SyncObjPoint,
|
||||
syncobj: &Rc<Syncobj>,
|
||||
point: SyncobjPoint,
|
||||
signaled: bool,
|
||||
sow: Rc<dyn SyncObjWaiter>,
|
||||
sow: Rc<dyn SyncobjWaiter>,
|
||||
) -> Result<(), DrmError> {
|
||||
let waiter = match self.inner.idle.pop() {
|
||||
Some(w) => w,
|
||||
|
|
@ -146,14 +146,14 @@ impl WaitForSyncObj {
|
|||
trigger: Default::default(),
|
||||
});
|
||||
Waiter {
|
||||
_task: self.eng.spawn("wait for sync obj", waiter.clone().run()),
|
||||
_task: self.eng.spawn("wait for syncobj", waiter.clone().run()),
|
||||
inner: waiter,
|
||||
}
|
||||
}
|
||||
};
|
||||
let job = Job {
|
||||
id: job_id,
|
||||
sync_obj: sync_obj.clone(),
|
||||
syncobj: syncobj.clone(),
|
||||
point,
|
||||
signaled,
|
||||
};
|
||||
|
|
@ -185,10 +185,10 @@ impl WaiterInner {
|
|||
|
||||
async fn wait(&self, buf: &mut Buf, job: &Job) -> Result<(), DrmError> {
|
||||
let ctx = match self.inner.ctx.get() {
|
||||
None => return Err(DrmError::NoSyncObjContextAvailable),
|
||||
None => return Err(DrmError::NoSyncobjContextAvailable),
|
||||
Some(c) => c,
|
||||
};
|
||||
ctx.wait_for_point(&self.eventfd, &job.sync_obj, job.point, job.signaled)?;
|
||||
ctx.wait_for_point(&self.eventfd, &job.syncobj, job.point, job.signaled)?;
|
||||
self.inner
|
||||
.ring
|
||||
.read(&self.eventfd, buf.clone())
|
||||
Loading…
Add table
Add a link
Reference in a new issue