1
This commit is contained in:
parent
c8ea47bcc8
commit
b7e2fd9e52
@ -30,6 +30,7 @@ pub struct XTimerAttacher {
|
||||
timers: TimerListListHeadRp,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum TimerType {
|
||||
Timeout,
|
||||
Interval
|
||||
@ -255,8 +256,7 @@ impl XTimer {
|
||||
}
|
||||
self.timer_tick += 1;
|
||||
|
||||
//println!("timer_tick:{} index:{} empty:{}", self.timer_tick, index, self.tv1[index].borrow().empty());
|
||||
crate::ListHead::<TimerList>::replace_init
|
||||
crate::ListHead::<TimerList>::replace_init
|
||||
(&self.tv1[index],
|
||||
&self.work_list);
|
||||
return true;
|
||||
@ -270,25 +270,34 @@ impl XTimer {
|
||||
let work_list = this.borrow().work_list.clone();
|
||||
while this.borrow_mut().fetch_work_list(tick) {
|
||||
while !work_list.borrow().empty() {
|
||||
let timer = &work_list.borrow().first_entry();
|
||||
this.borrow_mut().running_timer = timer.clone();
|
||||
match &mut timer.upgrade().unwrap().borrow_mut().cb {
|
||||
Some(v) => {
|
||||
(*v)(TimerEvent::Exec, None);
|
||||
}
|
||||
None => {
|
||||
{
|
||||
let timer = &work_list.borrow().first_entry();
|
||||
this.borrow_mut().running_timer = timer.clone();
|
||||
match &mut timer.upgrade().unwrap().borrow_mut().cb {
|
||||
Some(v) => {
|
||||
(*v)(TimerEvent::Exec, None);
|
||||
}
|
||||
None => {
|
||||
}
|
||||
}
|
||||
}
|
||||
let running_timer = this.borrow().running_timer.clone();
|
||||
match running_timer.upgrade() {
|
||||
Some(v) => {
|
||||
match v.borrow().timer_type {
|
||||
let timer_wp = Rc::downgrade(&v.borrow().wp.clone().unwrap());
|
||||
let timer_type = v.borrow().timer_type.clone();
|
||||
let expire_time = v.borrow().expire_time;
|
||||
match timer_type {
|
||||
TimerType::Timeout => {
|
||||
this.borrow_mut().internal_delete(Rc::downgrade(&v.borrow().wp.clone().unwrap()), false);
|
||||
this.borrow_mut().internal_delete
|
||||
(Rc::downgrade(&v.borrow().wp.clone().unwrap()),
|
||||
false);
|
||||
}
|
||||
TimerType::Interval => {
|
||||
this.borrow_mut().modify(Rc::downgrade(&v.borrow().wp.clone().unwrap()),
|
||||
v.borrow().expire_time);
|
||||
this.borrow_mut().internal_modify(
|
||||
timer_wp,
|
||||
expire_time
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -441,13 +450,14 @@ impl XTimer {
|
||||
}
|
||||
}
|
||||
|
||||
fn internal_modify(&mut self, timer_wp: XTimerWp, expire_time: i32) {
|
||||
fn internal_modify(&self, timer_wp: XTimerWp, expire_time: i32) {
|
||||
self.detach_timer(&timer_wp.upgrade().unwrap());
|
||||
timer_wp.upgrade().unwrap().borrow_mut().expire_time = expire_time;
|
||||
timer_wp.upgrade().unwrap().borrow_mut().expires =
|
||||
let timer = timer_wp.clone().upgrade().unwrap().clone();
|
||||
timer.borrow_mut().expire_time = expire_time;
|
||||
timer.borrow_mut().expires =
|
||||
(*self.get_tick_count.as_ref().unwrap())() +
|
||||
expire_time as i64;
|
||||
self.internal_add2(&timer_wp.upgrade().unwrap());
|
||||
self.internal_add2(&timer);
|
||||
}
|
||||
|
||||
pub fn set_timeout(&mut self, time: i32, cb: TimerCb) -> XTimerWp {
|
||||
@ -490,11 +500,11 @@ impl XTimer {
|
||||
pub fn modify(&mut self, timer_wp: XTimerWp, expire_time: i32) {
|
||||
match timer_wp.upgrade() {
|
||||
Some(_) => {
|
||||
self.internal_modify(timer_wp, expire_time);
|
||||
}
|
||||
None => {
|
||||
}
|
||||
}
|
||||
self.internal_modify(timer_wp, expire_time);
|
||||
}
|
||||
|
||||
pub fn delete_current_timer(&mut self) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user