pi_async_executor/
state.rs1use crate::parking::ThreadNotifier;
3use pi_async_runtime_core::definitions::{
4 CloseRequestStatus, CloseState, IdleState, RuntimeStatus,
5};
6use pi_async_task::Runnable;
7use pi_async_task_queue::{QueuePushError, TaskQueue};
8use std::sync::atomic::{AtomicU8, AtomicUsize};
9
10pub struct ExecutorState {
12 flags: AtomicU8,
13 idle: AtomicU8,
14 pub(crate) internal: AtomicUsize,
15 pub(crate) in_flight: AtomicUsize,
16}
17const CLOSE_REQUESTED: u8 = 1;
18const DRIVING: u8 = 2;
19const UNAVAILABLE: u8 = 4;
20const CLOSE_COMPLETE: u8 = 8;
21const CLEANUP_FAILED: u8 = 16;
22struct InternalCountGuard<'a> {
23 state: &'a ExecutorState,
24 armed: bool,
25}
26impl Drop for InternalCountGuard<'_> {
27 fn drop(&mut self) {
28 state_count_guard_drop_inner(self)
29 }
30}
31impl ExecutorState {
35 pub fn push_back(
38 &self,
39 queue: &mut TaskQueue,
40 task: Runnable,
41 ) -> pi_result::RawResult<(), QueuePushError> {
42 state_push_inner(self, queue, task, false)
43 }
44 pub fn push_front(
46 &self,
47 queue: &mut TaskQueue,
48 task: Runnable,
49 ) -> pi_result::RawResult<(), QueuePushError> {
50 state_push_inner(self, queue, task, true)
51 }
52 pub fn new() -> Self {
55 state_new_inner()
56 }
57 pub fn status(&self) -> RuntimeStatus {
58 state_status_inner(self)
59 }
60 pub fn close_state(&self) -> CloseState {
61 state_close_inner(self)
62 }
63 pub fn is_driving(&self) -> bool {
66 state_driving_inner(self)
67 }
68 pub fn last_idle_state(&self) -> IdleState {
69 state_idle_inner(self)
70 }
71 pub fn request_close(&self, notifier: &ThreadNotifier) -> CloseRequestStatus {
75 state_request_inner(self, notifier)
76 }
77 pub(crate) fn try_drive(&self) -> bool {
78 state_try_drive_inner(self)
79 }
80 pub(crate) fn release_drive(&self) {
81 state_release_drive_inner(self)
82 }
83 pub(crate) fn record_idle(&self, value: IdleState) {
84 state_record_idle_inner(self, value)
85 }
86 pub(crate) fn finish_owner(&self, failed_in_flight: usize, cleanup_failed: bool) {
87 state_finish_owner_inner(self, failed_in_flight, cleanup_failed)
88 }
89}
90include!("state_inner.rs");