use crate::device_events::{Event, EventApi};
#[cfg(multi_threading)]
use crate::memory_management::drop_queue;
use crate::server::ServerError;
pub struct EventFence<A: EventApi> {
event: Event<A>,
}
impl<A: EventApi> EventFence<A> {
pub fn new(stream: A::Stream) -> Self {
let event = Event::new().expect("the fence needs an event");
event
.record(stream)
.expect("the fence needs its event recorded");
Self { event }
}
pub fn wait_sync(self) -> Result<(), ServerError> {
Ok(self.event.wait()?)
}
pub fn wait_async(self, stream: A::Stream) {
self.event
.wait_async(stream)
.expect("the stream has to wait on the fence");
}
}
impl<A: EventApi> core::fmt::Debug for EventFence<A> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}Fence", A::BACKEND)
}
}
#[cfg(multi_threading)]
impl<A: EventApi> drop_queue::Fence for EventFence<A> {
fn wait(self) -> Result<(), ServerError> {
self.wait_sync()
}
}