This commit is contained in:
aozhiwei 2023-10-10 08:32:46 +08:00
parent 9adc663db0
commit aff0907a6b

View File

@ -40,7 +40,7 @@ struct TimerList {
expire_time: i32,
expires: i64,
cb: Option<Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>>,
cb: Option<Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>>,
}
pub struct Timer {
@ -82,14 +82,16 @@ impl Timer {
self.tv5[i] = crate::ListHead::<TimerList>::new_head();
}
self.timer_tick = (self.get_tick_count)();
/*
let cb = |e: i32, args: Option<Vec<Rc::<dyn Any>>>| {
};
let cb = Rc::new(
|e: i32, args: Option<Vec<Rc::<dyn Any>>>| {
//self.gc_timer(e, args);
}
);
self.set_interval(
gctime,
cb
);*/
);
}
pub fn uninit(&mut self) {
@ -102,11 +104,6 @@ impl Timer {
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
let mut p: Rc::<RefCell::<TimerList>>;
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
if Rc::weak_count(&p.borrow().wp) > 0 {
p.borrow_mut().wp = Rc::new(p.borrow().holder.clone());
}
/*
if self.free_timer_list.borrow().empty() {
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
if Rc::weak_count(&p.borrow().wp) > 0 {
@ -129,7 +126,7 @@ impl Timer {
Rc::downgrade(&p.borrow().holder)
);
p.borrow_mut().attach_entry = crate::ListHead::<TimerList>::new_head();
}*/
}
return p;
}
@ -140,7 +137,7 @@ impl Timer {
fn internal_add(&mut self,
timer_type: TimerType,
expire_time: i32,
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>,
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>,
attacher: Option<Rc::<RefCell::<TimerAttacher>>>) -> TimerWp {
let t = self.new_timer_list();
t.borrow_mut().cb = Some(cb);
@ -164,28 +161,28 @@ impl Timer {
pub fn set_timeout(&mut self,
expire_time: i32,
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>
) -> TimerWp {
return self.internal_add(TimerType::Timeout, expire_time, cb, None);
}
pub fn set_timeout_ex(&mut self,
expire_time: i32,
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>,
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>,
attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {
return self.internal_add(TimerType::Timeout, expire_time, cb, Some(attacher));
}
pub fn set_interval(&mut self,
expire_time: i32,
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>
) -> TimerWp {
return self.internal_add(TimerType::Interval, expire_time, cb, None);
}
pub fn set_interval_ex(&mut self,
expire_time: i32,
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>,
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>,
attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {
return self.internal_add(TimerType::Interval, expire_time, cb, Some(attacher));
}
@ -219,4 +216,8 @@ impl Timer {
return 0;
}
fn gc_timer(&mut self, e: i32, args: Option<Vec<Rc::<dyn Any>>>) {
}
}