1
This commit is contained in:
parent
edb6db8cb4
commit
e05caf1d81
40
src/timer.rs
40
src/timer.rs
@ -78,7 +78,7 @@ impl Timer {
|
|||||||
self.get_tick_count = get_tick_count;
|
self.get_tick_count = get_tick_count;
|
||||||
self.cache_timer_num = cache_timer_num;
|
self.cache_timer_num = cache_timer_num;
|
||||||
self.free_timer_num = 0;
|
self.free_timer_num = 0;
|
||||||
self.traverse_timer_list(
|
self.mut_traverse_timer_list(
|
||||||
&mut |timer_list: &mut TimerListListHeadRp| {
|
&mut |timer_list: &mut TimerListListHeadRp| {
|
||||||
*timer_list = crate::ListHead::<TimerList>::new_head();
|
*timer_list = crate::ListHead::<TimerList>::new_head();
|
||||||
});
|
});
|
||||||
@ -94,18 +94,32 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_timer_list(&mut self, cb: &mut dyn FnMut (&mut TimerListListHeadRp)) {
|
fn traverse_timer_list(&self, cb: &mut dyn FnMut (&TimerListListHeadRp)) {
|
||||||
|
(*cb)(&self.work_list);
|
||||||
|
let mut for_each_cb = |tv: &[TimerListListHeadRp]| {
|
||||||
|
for i in 0..tv.len() {
|
||||||
|
(*cb)(&tv[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for_each_cb(&self.tv1);
|
||||||
|
for_each_cb(&self.tv2);
|
||||||
|
for_each_cb(&self.tv3);
|
||||||
|
for_each_cb(&self.tv4);
|
||||||
|
for_each_cb(&self.tv5);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mut_traverse_timer_list(&mut self, cb: &mut dyn FnMut (&mut TimerListListHeadRp)) {
|
||||||
(*cb)(&mut self.work_list);
|
(*cb)(&mut self.work_list);
|
||||||
let mut init_timer_list = |tv: &mut [TimerListListHeadRp]| {
|
let mut for_each_cb = |tv: &mut [TimerListListHeadRp]| {
|
||||||
for i in 0..tv.len() {
|
for i in 0..tv.len() {
|
||||||
(*cb)(&mut tv[i]);
|
(*cb)(&mut tv[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
init_timer_list(&mut self.tv1);
|
for_each_cb(&mut self.tv1);
|
||||||
init_timer_list(&mut self.tv2);
|
for_each_cb(&mut self.tv2);
|
||||||
init_timer_list(&mut self.tv3);
|
for_each_cb(&mut self.tv3);
|
||||||
init_timer_list(&mut self.tv4);
|
for_each_cb(&mut self.tv4);
|
||||||
init_timer_list(&mut self.tv5);
|
for_each_cb(&mut self.tv5);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shared_from_self(&self) -> Rc::<RefCell::<Timer>> {
|
fn shared_from_self(&self) -> Rc::<RefCell::<Timer>> {
|
||||||
@ -124,17 +138,17 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
let free_timer = |head: &mut TimerListListHeadRp| {
|
let free_timer = |head: &TimerListListHeadRp| {
|
||||||
while !head.borrow().empty() {
|
while !head.borrow().empty() {
|
||||||
let timer = &head.borrow().first_entry().upgrade().unwrap();
|
let timer = &head.borrow().first_entry().upgrade().unwrap();
|
||||||
timer.borrow_mut().timer_entry.borrow_mut().del_init();
|
//self.detach_timer(timer);
|
||||||
if timer.borrow().attach_entry.borrow().empty() {
|
if timer.borrow().attach_entry.borrow().empty() {
|
||||||
timer.borrow().attach_entry.borrow_mut().del_init();
|
timer.borrow().attach_entry.borrow_mut().del_init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.traverse_timer_list(
|
self.traverse_timer_list(
|
||||||
&mut |timer_list: &mut TimerListListHeadRp| {
|
&mut |timer_list: &TimerListListHeadRp| {
|
||||||
free_timer(timer_list);
|
free_timer(timer_list);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -387,9 +401,9 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detach_timer(&mut self, timer: &Rc::<RefCell::<TimerList>>) {
|
fn detach_timer(&self, timer: &Rc::<RefCell::<TimerList>>) {
|
||||||
if !timer.borrow().timer_entry.borrow().empty() {
|
if !timer.borrow().timer_entry.borrow().empty() {
|
||||||
|
timer.borrow().timer_entry.borrow_mut().del_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user