pub struct OrderedTimerDeque<DQI: OrderedTimerDequeIntrf + Ord + PartialOrd + PartialEq + Eq + Debug + Display> { /* 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.
§Generics
DQI- a deque type. There are three types are available:-
- crate::TimerDequeueTicketIssuer issues a ticket for the instance for which the timer was set.
ⓘlet mut time_list = OrderedTimerDeque ::<TimerDequeueTicketIssuer> ::new("test_label".into(), 4, false).unwrap();-
- crate::TimerDequeueConsumer consumes the instance for which the timer is set.
ⓘlet mut time_list = OrderedTimerDeque ::<TimerDequeueConsumer<TestItem>> ::new("test_label".into(), 4, false).unwrap();-
- crate::TimerDequeueSignalTicket sends a signal to destination.
ⓘlet mut time_list = OrderedTimerDeque ::<TimerDequeueSignalTicket<TestSigStruct>> ::new("test_label".into(), 4, false).unwrap();-
Implementations§
Source§impl<R> OrderedTimerDeque<TimerDequeueConsumer<R>>
impl<R> OrderedTimerDeque<TimerDequeueConsumer<R>>
Sourcepub fn add_to_timer(
&mut self,
entity: R,
abs_time_sec: i64,
abs_time_nsec: i64,
) -> TimerResult<NoTicket>
pub fn add_to_timer( &mut self, entity: R, abs_time_sec: i64, abs_time_nsec: i64, ) -> 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_sec - a i64 absolute time in seconds. Can not be 0.
abs_time_nsec - a i64 asolute time in nanosecodns. Can be 0.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the common::NoTicket ticket which is dummy value.
-
Result::Err with error description.
Sourcepub fn remove_from_sched_queue(&mut self, entity: &R) -> TimerResult<Option<R>>
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:
-
Result::Ok with the inner type Option where
- Option::Some is returned with the consumed
entity. - Option::None is returned when item was not found.
- Option::Some is returned with the consumed
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
timeout_items: &mut Vec<R>,
) -> TimerResult<()>
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:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl OrderedTimerDeque<TimerDequeueTicketIssuer>
impl OrderedTimerDeque<TimerDequeueTicketIssuer>
Sourcepub fn add_to_timer(
&mut self,
abs_time_sec: i64,
abs_time_nsec: i64,
) -> TimerResult<TimerDequeueTicket>
pub fn add_to_timer( &mut self, abs_time_sec: i64, abs_time_nsec: i64, ) -> TimerResult<TimerDequeueTicket>
Adds the new absolute timeout to the timer dequeue.
§Arguemnts
abs_time_sec - a i64 absolute time in seconds. Can not be 0.
abs_time_nsec - a i64 asolute time in nanosecodns. Can be 0.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the TimerDequeueTicket ticket.
-
Result::Err with error description.
Sourcepub fn remove_from_sched_queue(
&mut self,
ticket: TimerDequeueTicket,
) -> TimerResult<()>
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:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
timeout_items: &mut Vec<TimerDequeueId>,
) -> TimerResult<()>
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 tickets which were not dropped and timeout.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG>>
impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG>>
Sourcepub fn add_to_timer(
&mut self,
sig_hnd: SIG,
abs_time_sec: i64,
abs_time_nsec: i64,
) -> TimerResult<NoTicket>
pub fn add_to_timer( &mut self, sig_hnd: SIG, abs_time_sec: i64, abs_time_nsec: i64, ) -> TimerResult<NoTicket>
Adds the new absolute timeout to the timer dequeue.
§Arguemnts
sig_hnd - a SIG generic instance which would identify the instance and
provide identification.
abs_time_sec - a i64 absolute time in seconds. Can not be 0.
abs_time_nsec - a i64 asolute time in nanosecodns. Can be 0.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the [TimerDequeueTicket] ticket.
-
Result::Err with error description.
Sourcepub fn remove_from_sched_queue(
&mut self,
arg_uniq_id: &SIG::TimerQueueID,
) -> TimerResult<Option<()>>
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:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
) -> TimerResult<()>
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:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Sourcepub async fn async_timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
) -> TimerResult<()>
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:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<DQI> OrderedTimerDeque<DQI>
impl<DQI> OrderedTimerDeque<DQI>
Sourcepub fn new(
timer_label: Cow<'static, str>,
deq_len: usize,
cloexec: bool,
) -> TimerResult<OrderedTimerDeque<DQI>>
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
-
Result::Ok with the instance.
-
Result::Err with the error description.
Sourcepub fn wait_for_event(&self) -> TimerResult<TimerReadRes<u64>>
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
-
In case of
EAGAIN, the TimerReadRes::WouldBlock will be returned. -
In case of
ECANCELLD, the TimerReadRes::WouldBlock will be returned. -
In case of any other error the Result::Err is returned.
When a timer fires an event the Result::Ok is returned with the amount of timer overrun. Normally it is 1.
Sourcepub async fn poll(&self) -> TimerResult<TimerReadRes<u64>>
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.
Sourcepub fn timer_queue_len(&self) -> usize
pub fn timer_queue_len(&self) -> usize
Returns the queue length.
Sourcepub fn reschedule_timer(&mut self) -> TimerResult<()>
pub fn reschedule_timer(&mut self) -> TimerResult<()>
Setting the timer instance to the new values or unsets the timer if
queue becomes empty.
Sourcepub fn clean_up_timer(&mut self) -> TimerResult<()>
pub fn clean_up_timer(&mut self) -> TimerResult<()>
Unarms timer and clears the queue.
Sourcepub fn stop_timer(&mut self) -> TimerResult<()>
pub fn stop_timer(&mut self) -> TimerResult<()>
Unarms timer only.