use crate::parking::ThreadNotifier;
use pi_async_runtime_core::definitions::{
CloseRequestStatus, CloseState, IdleState, RuntimeStatus,
};
use pi_async_task::Runnable;
use pi_async_task_queue::{QueuePushError, TaskQueue};
use std::sync::atomic::{AtomicU8, AtomicUsize};
pub struct ExecutorState {
flags: AtomicU8,
idle: AtomicU8,
pub(crate) internal: AtomicUsize,
pub(crate) in_flight: AtomicUsize,
}
const CLOSE_REQUESTED: u8 = 1;
const DRIVING: u8 = 2;
const UNAVAILABLE: u8 = 4;
const CLOSE_COMPLETE: u8 = 8;
const CLEANUP_FAILED: u8 = 16;
struct InternalCountGuard<'a> {
state: &'a ExecutorState,
armed: bool,
}
impl Drop for InternalCountGuard<'_> {
fn drop(&mut self) {
state_count_guard_drop_inner(self)
}
}
impl ExecutorState {
pub fn push_back(
&self,
queue: &mut TaskQueue,
task: Runnable,
) -> pi_result::RawResult<(), QueuePushError> {
state_push_inner(self, queue, task, false)
}
pub fn push_front(
&self,
queue: &mut TaskQueue,
task: Runnable,
) -> pi_result::RawResult<(), QueuePushError> {
state_push_inner(self, queue, task, true)
}
pub fn new() -> Self {
state_new_inner()
}
pub fn status(&self) -> RuntimeStatus {
state_status_inner(self)
}
pub fn close_state(&self) -> CloseState {
state_close_inner(self)
}
pub fn is_driving(&self) -> bool {
state_driving_inner(self)
}
pub fn last_idle_state(&self) -> IdleState {
state_idle_inner(self)
}
pub fn request_close(&self, notifier: &ThreadNotifier) -> CloseRequestStatus {
state_request_inner(self, notifier)
}
pub(crate) fn try_drive(&self) -> bool {
state_try_drive_inner(self)
}
pub(crate) fn release_drive(&self) {
state_release_drive_inner(self)
}
pub(crate) fn record_idle(&self, value: IdleState) {
state_record_idle_inner(self, value)
}
pub(crate) fn finish_owner(&self, failed_in_flight: usize, cleanup_failed: bool) {
state_finish_owner_inner(self, failed_in_flight, cleanup_failed)
}
}
include!("state_inner.rs");