qubit_thread_pool/delayed/delayed_task_scheduler_state.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use std::collections::BinaryHeap;
11
12use qubit_executor::service::ExecutorServiceLifecycle;
13
14use super::scheduled_task::ScheduledTask;
15
16/// Mutable scheduler state protected by the scheduler mutex.
17pub struct DelayedTaskSchedulerState {
18 /// Current lifecycle state.
19 pub lifecycle: ExecutorServiceLifecycle,
20 /// Deadline-ordered task heap.
21 pub tasks: BinaryHeap<ScheduledTask>,
22 /// Sequence used to keep stable order for identical deadlines.
23 pub next_sequence: usize,
24 /// Whether the scheduler thread has exited.
25 pub terminated: bool,
26}
27
28impl DelayedTaskSchedulerState {
29 /// Creates an empty running scheduler state.
30 ///
31 /// # Returns
32 ///
33 /// A running state with no queued delayed tasks.
34 pub(crate) fn new() -> Self {
35 Self {
36 lifecycle: ExecutorServiceLifecycle::Running,
37 tasks: BinaryHeap::new(),
38 next_sequence: 0,
39 terminated: false,
40 }
41 }
42}