OrderedTimerDeque

Struct OrderedTimerDeque 

Source
pub struct OrderedTimerDeque<DQI: OrderedTimerDequeIntrf> { /* private fields */ }
Expand description

A VecDeque based queue which is sorted (in ascending order) by the timeout which is absolute time.

The queue automatically manages the timer i.e setting, unsetting.

Also for each type of the deque, a event procesing function is providided.

There are two types of queue:

§Generics

  • DQI - a deque type. There are three types are available:
        let mut time_list = 
            OrderedTimerDeque
                ::<TimerDequeueTicketIssuer<OrderdTimerDequeOnce>>
                ::new("test_label".into(), 4, false).unwrap();
    or
        let mut time_list = 
            OrderedTimerDeque
                ::<TimerDequeueTicketIssuer<OrderdTimerDequePeriodic>>
                ::new("test_label".into(), 4, false).unwrap();
        let mut time_list = 
            OrderedTimerDeque
                ::<TimerDequeueConsumer<TestItem, OrderdTimerDequeOnce>>
                ::new("test_label".into(), 4, false).unwrap();
    or
        let mut time_list = 
            OrderedTimerDeque
                ::<TimerDequeueConsumer<TestItem, OrderdTimerDequePeriodic>>
                ::new("test_label".into(), 4, false).unwrap();
        let mut time_list = 
            OrderedTimerDeque
                ::<TimerDequeueSignalTicket<TestSigStruct, OrderdTimerDequeOnce>>
                ::new("test_label".into(), 4, false).unwrap();
    or
        let mut time_list = 
            OrderedTimerDeque
                ::<TimerDequeueSignalTicket<TestSigStruct, OrderdTimerDequePeriodic>>
                ::new("test_label".into(), 4, false).unwrap();

Implementations§

Source§

impl<R> OrderedTimerDeque<TimerDequeueConsumer<R, OrderdTimerDequeOnce>>
where R: PartialEq + Eq + Display + Debug + Send,

Source

pub fn add_to_timer( &mut self, entity: R, abs_time: AbsoluteTime, ) -> TimerResult<NoTicket>

Adds the new absolute timeout to the timer dequeue instance.

The entity is an item which should be stored in the dequeue.

§Arguemnts

entity - R generic which is an item to store in the dequeu.

abs_time - a AbsoluteTime absolute time in future when the timeout should happen.

§Returns

A Result as alias TimerResult is returned with:

Source

pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<R>, ) -> TimerResult<()>

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of an enitities for which timeout have happened.

A Result as alias TimerResult is returned with:

Source§

impl<R> OrderedTimerDeque<TimerDequeueConsumer<R, OrderdTimerDequePeriodic>>
where R: PartialEq + Eq + Display + Debug + Send + Clone,

Source

pub fn add_to_timer( &mut self, entity: R, rel_time: RelativeTime, ) -> TimerResult<NoTicket>

Adds the new entry to the timout queue which after alarm extends the timeout and sets the instance in the queue again.

The entity is an item which should be stored in the dequeue and impl Clone.

§Arguemnts

entity - R generic which is an item to store in the dequeu.

rel_time - a RelativeTime which will be used to extend the further timeouts.

§Returns

A Result as alias TimerResult is returned with:

Source

pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<R>, ) -> TimerResult<()>

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of an enitities for which timeout have happened.

A Result as alias TimerResult is returned with:

Source§

impl<R, MODE> OrderedTimerDeque<TimerDequeueConsumer<R, MODE>>

Source

pub fn remove_from_sched_queue(&mut self, entity: &R) -> TimerResult<Option<R>>

Removes the instance from the queue by the reference to entity.

§Arguments

entity - R reference to added item which will be used to identify the item ont he record.

§Returns

A Result as alias TimerResult is returned with:

Source§

impl OrderedTimerDeque<TimerDequeueTicketIssuer<OrderdTimerDequeOnce>>

Source

pub fn add_to_timer( &mut self, abs_time: AbsoluteTime, ) -> TimerResult<TimerDequeueTicket>

Adds the new entry to the timeout qeueu which after alarm removes the entry from the queue. A ticket will be issued which can be used to either deactivate the record by droppping it or to remove it manually.

§Arguemnts

abs_time - a AbsoluteTime absolute time in future when the timeout should happen.

§Returns

A Result as alias TimerResult is returned with:

Source

pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<TimerDequeueId>, ) -> TimerResult<()>

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of an enitities for which timeout have happened.

A Result as alias TimerResult is returned with:

Source§

impl OrderedTimerDeque<TimerDequeueTicketIssuer<OrderdTimerDequePeriodic>>

Source

pub fn add_to_timer( &mut self, rel_time: RelativeTime, ) -> TimerResult<TimerDequeueTicket>

Adds the new entry to the timeout queue which after alarm extends the timeout and sets the instance in the queue again. A ticket will be issued which can be used to either deactivate the record by droppping it or to remove it manually.

§Arguemnts

rel_time - a RelativeTime which will be used to extend the further timeouts. .

§Returns

A Result as alias TimerResult is returned with:

Source

pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<TimerDequeueId>, ) -> TimerResult<()>

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of an enitities for which timeout have happened.

A Result as alias TimerResult is returned with:

Source§

impl<MODE: OrderedTimerDequeMode> OrderedTimerDeque<TimerDequeueTicketIssuer<MODE>>

Source

pub fn remove_from_sched_queue( &mut self, ticket: TimerDequeueTicket, ) -> TimerResult<()>

Removes the instance from the queue by the issued ticket.

§Arguments

ticket - TimerDequeueTicket an issued ticket.

§Returns

A Result as alias TimerResult is returned with:

Source§

impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, OrderdTimerDequeOnce>>
where SIG: TimerDequeueSignal,

Source

pub fn add_to_timer( &mut self, sig_hnd: SIG, abs_time: AbsoluteTime, ) -> TimerResult<NoTicket>

Adds the new absolute (relative) timeout to the timer dequeue.

§Arguemnts

sig_hnd - a SIG generic instance which would identify the instance and provide identification.

abs_time - a AbsoluteTime absolute time in future when the timeout should happen.

§Returns

A Result as alias TimerResult is returned with:

Source

pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of tickets which were not dropped and timeout.

A Result as alias TimerResult is returned with:

Source

pub async fn async_timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>

An async version of the event handler.

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of tickets which were not dropped and timeout.

A Result as alias TimerResult is returned with:

Source§

impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, OrderdTimerDequePeriodic>>
where SIG: TimerDequeueSignal,

Source

pub fn add_to_timer( &mut self, sig_hnd: SIG, rel_time: RelativeTime, ) -> TimerResult<NoTicket>

Adds the new periodic timeout to the timer dequeue.

§Arguemnts

sig_hnd - a SIG generic instance which would identify the instance and provide identification.

rel_time - a RelativeTime which will be used to extend the further timeouts.

§Returns

A Result as alias TimerResult is returned with:

Source

pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of tickets which were not dropped and timeout.

A Result as alias TimerResult is returned with:

Source

pub async fn async_timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>

An async version of the event handler.

Handles the event which was read from the timer. The functions Self::wait_for_event or Self::poll can be used to obtain the event.

§Arguments

res - TimerReadRes an event from the timer to handle.

timeout_items - a vector of tickets which were not dropped and timeout.

A Result as alias TimerResult is returned with:

Source§

impl<SIG, MODE> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, MODE>>

Source

pub fn remove_from_sched_queue( &mut self, arg_uniq_id: &SIG::TimerQueueID, ) -> TimerResult<Option<()>>

Removes the instance from the queue by the SIG::TimerQueueID ID.

§Arguments

arg_uniq_id - a reference to instance’s ID SIG::TimerQueueID.

§Returns

A Result as alias TimerResult is returned with:

Source§

impl<DQI> OrderedTimerDeque<DQI>

Source

pub fn new( timer_label: Cow<'static, str>, deq_len: usize, cloexec: bool, ) -> TimerResult<OrderedTimerDeque<DQI>>

Creates new deque instance.

§Argument

timer_label - a label which helps to identify the timer.

deq_len - a minimal, pre-allocated deque length.

cloexec - when set to true sets the CLOEXEC flag to FD.

§Returns

A Result as alias TimerResult is returned with

Source

pub fn wait_for_event(&self) -> TimerResult<TimerReadRes<u64>>

Reads the FD to retrive the event type.

This function behaves differently when the timer is set with TimerFlags::TFD_NONBLOCK.

Normally, all timer_* creates nonblocking timer, so this function behaves like when the TimerFlags::TFD_NONBLOCK is set.

When TimerFlags::TFD_NONBLOCK is not set, this function will block reading the FD. In case of ‘EINTR’, the read attempt will be repeated. It will be reapeated in both cases.

When TimerFlags::TFD_NONBLOCK is set, the function will return with some result.

§Return

When a timer fires an event the Result::Ok is returned with the amount of timer overrun. Normally it is 1.

Source

pub async fn poll(&self) -> TimerResult<TimerReadRes<u64>>

Asynchronious polling. The timer’s FD is set to nonblocking, so each time it will return pending and load CPU. If you are using tokio or smol suing corresponding helpers like tokio’s AsyncFd.

Source

pub fn timer_queue_len(&self) -> usize

Returns the queue length.

Source

pub fn reschedule_timer(&mut self) -> TimerResult<()>

Setting the timer instance to the new values or unsets the timer if queue becomes empty.

Source

pub fn clean_up_timer(&mut self) -> TimerResult<()>

Unarms timer and clears the queue.

Source

pub fn stop_timer(&mut self) -> TimerResult<()>

Unarms timer only.

Trait Implementations§

Source§

impl<DQI> AsFd for OrderedTimerDeque<DQI>

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl<DQI> AsRawFd for OrderedTimerDeque<DQI>

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl<DQI> AsTimerFd for OrderedTimerDeque<DQI>

Source§

fn get_bind(&self) -> Option<Arc<DefaultEventWatch>>

Should return the upgraded reference to which instance it is bind. Read more
Source§

fn bind_poll(&self, timer_weak_ref: Weak<DefaultEventWatch>)

Regesters poller DefaultEventWatch on the timer’s record. Read more
Source§

fn unbind_poll(&self)

Removes bind fromt the timer.
Source§

impl<DQI: Debug + OrderedTimerDequeIntrf> Debug for OrderedTimerDeque<DQI>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DQI> Display for OrderedTimerDeque<DQI>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DQI> Drop for OrderedTimerDeque<DQI>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<DQI> !Freeze for OrderedTimerDeque<DQI>

§

impl<DQI> RefUnwindSafe for OrderedTimerDeque<DQI>
where DQI: RefUnwindSafe,

§

impl<DQI> Send for OrderedTimerDeque<DQI>
where DQI: Send,

§

impl<DQI> Sync for OrderedTimerDeque<DQI>
where DQI: Sync,

§

impl<DQI> Unpin for OrderedTimerDeque<DQI>
where DQI: Unpin,

§

impl<DQI> UnwindSafe for OrderedTimerDeque<DQI>
where DQI: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V