1
This commit is contained in:
parent
389f5a06ce
commit
746fe5b87c
75
src/timer.rs
75
src/timer.rs
@ -75,33 +75,47 @@ impl Timer {
|
|||||||
get_tick_count: fn () -> i64,
|
get_tick_count: fn () -> i64,
|
||||||
gctime: i32,
|
gctime: i32,
|
||||||
cache_timer_num: i32) {
|
cache_timer_num: i32) {
|
||||||
let init_timer_list = |tv: &mut [TimerListListHeadRp]| {
|
|
||||||
for i in 0..tv.len() {
|
|
||||||
tv[i] = crate::ListHead::<TimerList>::new_head();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.work_list = crate::ListHead::<TimerList>::new_head();
|
self.work_list = crate::ListHead::<TimerList>::new_head();
|
||||||
init_timer_list(&mut self.tv1);
|
/*self.traverse_timer_list(
|
||||||
init_timer_list(&mut self.tv2);
|
&mut |timer_list: &mut TimerListListHeadRp| {
|
||||||
|
timer_list = crate::ListHead::<TimerList>::new_head();
|
||||||
|
});*/
|
||||||
|
self.timer_tick = (self.get_tick_count)();
|
||||||
|
{
|
||||||
|
let self_wp = self.shared_from_self();
|
||||||
|
let cb = Box::new(
|
||||||
|
move |event: TimerEvent, args: Option<Vec<Rc::<dyn Any>>>| {
|
||||||
|
self_wp.borrow_mut().gc_timer(event, args);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
self.set_interval(gctime, cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn traverse_timer_list(&mut self, cb: Box::<dyn FnMut (&mut TimerListListHeadRp)>) {
|
||||||
|
let init_timer_list = |tv: &mut [TimerListListHeadRp]| {
|
||||||
|
for i in 0..tv.len() {
|
||||||
|
//(*cb)(&mut self.work_list);
|
||||||
|
//(*cb)(&mut tv[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
(*cb)(&mut self.work_list);
|
||||||
|
/*
|
||||||
|
match &mut cb {
|
||||||
|
Some(v) => {
|
||||||
|
(*v)(&mut self.work_list);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
//init_timer_list(&mut self.tv1);
|
||||||
|
/*init_timer_list(&mut self.tv2);
|
||||||
init_timer_list(&mut self.tv3);
|
init_timer_list(&mut self.tv3);
|
||||||
init_timer_list(&mut self.tv4);
|
init_timer_list(&mut self.tv4);
|
||||||
init_timer_list(&mut self.tv5);
|
init_timer_list(&mut self.tv5);*/
|
||||||
self.timer_tick = (self.get_tick_count)();
|
|
||||||
let self_wp = self.shared_from_self();
|
|
||||||
let cb = Box::new(
|
|
||||||
move |event: TimerEvent, args: Option<Vec<Rc::<dyn Any>>>| {
|
|
||||||
self_wp.borrow_mut().gc_timer(event, args);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
self.set_interval(
|
|
||||||
gctime,
|
|
||||||
cb,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shared_from_self(&self) -> Rc::<RefCell::<Timer>> {
|
fn shared_from_self(&self) -> Rc::<RefCell::<Timer>> {
|
||||||
@ -120,7 +134,24 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
|
let free_timer = |tv: &mut [TimerListListHeadRp]| {
|
||||||
|
for i in 0..tv.len() {
|
||||||
|
let head = &tv[i];
|
||||||
|
while !head.borrow().empty() {
|
||||||
|
let timer = &head.borrow().first_entry().upgrade().unwrap();
|
||||||
|
timer.borrow_mut().timer_entry.borrow_mut().del_init();
|
||||||
|
if timer.borrow().attach_entry.borrow().empty() {
|
||||||
|
timer.borrow().attach_entry.borrow_mut().del_init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//free_timer(&mut self.free_timer_list);
|
||||||
|
free_timer(&mut self.tv1);
|
||||||
|
free_timer(&mut self.tv2);
|
||||||
|
free_timer(&mut self.tv3);
|
||||||
|
free_timer(&mut self.tv4);
|
||||||
|
free_timer(&mut self.tv5);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
|
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user