use pi_async_executor::ExecutorTimer;
use pi_async_task_queue::{ExternalQueueManager, ExternalTaskQueue, IdleQueueManager, IdleTaskQueue};
use crate::{
access::{self, BindingExitGuard},
instance::*,
lifecycle::RuntimeBinding,
mode::RuntimeMode,
};
use pi_async_executor::{DriveLease, ExecutorClock, ExecutorHooks, IdlePolicy, TurnResult};
use pi_async_runtime_core::{
block_on::{BlockOnDriver, RootWakeState},
RuntimeBlockOn, RuntimeQuery, RuntimeStatus,
};
use pi_clock_manual::global::GlobalManualInstant;
use std::future::Future;
struct RuntimeDriver<'a, M, C, P, H, E, I, T>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
{
data: &'a mut RuntimeData<M, C, P, H, E, I, T>,
lease: DriveLease,
last: Option<TurnResult>,
binding: &'a RuntimeBinding,
handle: &'a RuntimeHandle<C, E::Handle, I::Handle, T>,
}
impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
{
pub fn run_once(&mut self) -> pi_result::Result<TurnResult> {
runtime_once_inner(self)
}
pub fn run(&mut self) -> pi_result::Result<()> {
runtime_run_inner(self)
}
}
impl<C, E, I, T> RuntimeBlockOn for RuntimeHandle<C, E, I, T>
where
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalTaskQueue,
I: IdleTaskQueue,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
{
fn block_on<F: Future>(&self, future: F) -> F::Output {
handle_block_on_inner(self, future)
}
}
impl<M, C, P, H, E, I, T> RuntimeBlockOn for ConfiguredRuntime<M, C, P, H, E, I, T>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
{
fn block_on<F: Future>(&self, future: F) -> F::Output {
runtime_block_on_inner(self, future)
}
}
impl<M, C, P, H, E, I, T> BlockOnDriver for RuntimeDriver<'_, M, C, P, H, E, I, T>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
{
fn turn(&mut self) -> bool {
runtime_driver_turn_inner(self)
}
fn park(&mut self, root: &RootWakeState) {
runtime_driver_park_inner(self, root)
}
}
include!("driving_inner.rs");