pub struct TaskPriorityQueue { /* private fields */ }Expand description
A priority queue for tasks.
Implementations§
Source§impl TaskPriorityQueue
impl TaskPriorityQueue
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a queue with a maximum capacity.
Sourcepub fn set_age_bump_amount(&mut self, amount: u32)
pub fn set_age_bump_amount(&mut self, amount: u32)
Set the aging bump amount.
Sourcepub fn push(&mut self, task: PriorityTask) -> bool
pub fn push(&mut self, task: PriorityTask) -> bool
Push a task into the queue.
Returns false if the queue is at capacity.
Sourcepub fn pop(&mut self) -> Option<PriorityTask>
pub fn pop(&mut self) -> Option<PriorityTask>
Pop the highest-priority task.
Sourcepub fn peek(&self) -> Option<&PriorityTask>
pub fn peek(&self) -> Option<&PriorityTask>
Peek at the highest-priority task without removing it.
Sourcepub fn apply_aging(&mut self)
pub fn apply_aging(&mut self)
Apply aging: bump the priority of all non-critical tasks.
This prevents starvation of low-priority tasks by gradually increasing their effective priority.
Sourcepub fn remove_expired(&mut self, now_ms: u64) -> Vec<PriorityTask>
pub fn remove_expired(&mut self, now_ms: u64) -> Vec<PriorityTask>
Remove all tasks that have passed their deadline.
now_ms is the current timestamp in milliseconds.
Returns the expired tasks.
Sourcepub fn drain_priority(&mut self, priority: Priority) -> Vec<PriorityTask>
pub fn drain_priority(&mut self, priority: Priority) -> Vec<PriorityTask>
Drain all tasks with a given priority.
Sourcepub fn try_preempt(&mut self, incoming: PriorityTask) -> Option<PriorityTask>
pub fn try_preempt(&mut self, incoming: PriorityTask) -> Option<PriorityTask>
Attempt to preempt (replace) the lowest-priority task if incoming
has strictly higher effective weight.
Returns the displaced task if preemption occurred, or None when the
queue is not full, the queue is empty, or incoming does not outrank
the current minimum.
Preemption is only meaningful when the queue is at capacity; callers
should call push directly when capacity has not been reached.
Sourcepub fn would_preempt(&self, incoming: &PriorityTask) -> bool
pub fn would_preempt(&self, incoming: &PriorityTask) -> bool
Check whether the given task would preempt the current lowest-priority occupant without actually performing the preemption.
Trait Implementations§
Source§impl Debug for TaskPriorityQueue
impl Debug for TaskPriorityQueue
Auto Trait Implementations§
impl Freeze for TaskPriorityQueue
impl RefUnwindSafe for TaskPriorityQueue
impl Send for TaskPriorityQueue
impl Sync for TaskPriorityQueue
impl Unpin for TaskPriorityQueue
impl UnsafeUnpin for TaskPriorityQueue
impl UnwindSafe for TaskPriorityQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request