This commit is contained in:
aozhiwei 2023-10-29 13:54:11 +08:00
parent c8ea47bcc8
commit b7e2fd9e52

View File

@ -30,6 +30,7 @@ pub struct XTimerAttacher {
timers: TimerListListHeadRp, timers: TimerListListHeadRp,
} }
#[derive(Clone)]
enum TimerType { enum TimerType {
Timeout, Timeout,
Interval Interval
@ -255,7 +256,6 @@ impl XTimer {
} }
self.timer_tick += 1; 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.tv1[index],
&self.work_list); &self.work_list);
@ -270,6 +270,7 @@ impl XTimer {
let work_list = this.borrow().work_list.clone(); let work_list = this.borrow().work_list.clone();
while this.borrow_mut().fetch_work_list(tick) { while this.borrow_mut().fetch_work_list(tick) {
while !work_list.borrow().empty() { while !work_list.borrow().empty() {
{
let timer = &work_list.borrow().first_entry(); let timer = &work_list.borrow().first_entry();
this.borrow_mut().running_timer = timer.clone(); this.borrow_mut().running_timer = timer.clone();
match &mut timer.upgrade().unwrap().borrow_mut().cb { match &mut timer.upgrade().unwrap().borrow_mut().cb {
@ -279,16 +280,24 @@ impl XTimer {
None => { None => {
} }
} }
}
let running_timer = this.borrow().running_timer.clone(); let running_timer = this.borrow().running_timer.clone();
match running_timer.upgrade() { match running_timer.upgrade() {
Some(v) => { 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 => { 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 => { TimerType::Interval => {
this.borrow_mut().modify(Rc::downgrade(&v.borrow().wp.clone().unwrap()), this.borrow_mut().internal_modify(
v.borrow().expire_time); 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()); self.detach_timer(&timer_wp.upgrade().unwrap());
timer_wp.upgrade().unwrap().borrow_mut().expire_time = expire_time; let timer = timer_wp.clone().upgrade().unwrap().clone();
timer_wp.upgrade().unwrap().borrow_mut().expires = timer.borrow_mut().expire_time = expire_time;
timer.borrow_mut().expires =
(*self.get_tick_count.as_ref().unwrap())() + (*self.get_tick_count.as_ref().unwrap())() +
expire_time as i64; 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 { 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) { pub fn modify(&mut self, timer_wp: XTimerWp, expire_time: i32) {
match timer_wp.upgrade() { match timer_wp.upgrade() {
Some(_) => { Some(_) => {
self.internal_modify(timer_wp, expire_time);
} }
None => { None => {
} }
} }
self.internal_modify(timer_wp, expire_time);
} }
pub fn delete_current_timer(&mut self) { pub fn delete_current_timer(&mut self) {