use std::time;
use dope_sys::{
engine::{self, ring},
ring::{Source, ready::Ready as _},
};
use o3::mem::quota;
use crate::{
Engine, Uring,
driver::tuning::{self, Progress as _},
};
impl<C: ring::Context> engine::raw::Poll for Engine<C>
where
C::Tuning: tuning::Progress<C::Token>,
{
type Context = C;
type Error = <Uring as Source>::Poll;
unsafe fn wait<'a, Tag>(
&'a mut self,
quota: quota::Shared<'_, Tag>,
timeout: Option<time::Duration>,
busy: bool,
) -> Result<(), Self::Error>
where
C: 'a,
{
drop(quota);
if busy || self.tuning.has_pending() || timeout.is_some_and(|span| span.is_zero()) {
self.ring.commit()
} else {
self.ring.try_wait(timeout)
}
}
}