TimerQueue

Struct TimerQueue 

Source
pub struct TimerQueue {
    queue: BTreeMap<usize, Arc<SpinLock<Task>>>,
}
Expand description

定时器队列,用于管理定时任务

Fields§

§queue: BTreeMap<usize, Arc<SpinLock<Task>>>

以触发时间为键,任务为值的有序映射

Implementations§

Source§

impl TimerQueue

Source

pub fn new() -> Self

创建一个新的定时器队列

Source

pub fn push(&mut self, trigger_time: usize, task: Arc<SpinLock<Task>>)

向队列中添加一个定时任务

§参数:
  • trigger_time: 任务触发的时间点
  • task: 需要执行的任务
Source

pub fn pop_due_task( &mut self, current_time: usize, ) -> Option<Arc<SpinLock<Task>>>

弹出已到期的任务

§参数:
  • current_time: 当前时间点
§返回值:
  • 已到期的任务(如果有)
Source

pub fn remove_task( &mut self, task: &Arc<SpinLock<Task>>, ) -> Option<Arc<SpinLock<Task>>>

移除指定任务

§参数:
  • task: 需要移除的任务
§返回值:
  • 被移除的任务(如果存在)

Auto Trait Implementations§

§

impl Freeze for TimerQueue

§

impl !RefUnwindSafe for TimerQueue

§

impl Send for TimerQueue

§

impl Sync for TimerQueue

§

impl Unpin for TimerQueue

§

impl !UnwindSafe for TimerQueue

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.