1
This commit is contained in:
parent
9adc663db0
commit
aff0907a6b
33
src/timer.rs
33
src/timer.rs
@ -40,7 +40,7 @@ struct TimerList {
|
|||||||
expire_time: i32,
|
expire_time: i32,
|
||||||
expires: i64,
|
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 {
|
pub struct Timer {
|
||||||
@ -82,14 +82,16 @@ impl Timer {
|
|||||||
self.tv5[i] = crate::ListHead::<TimerList>::new_head();
|
self.tv5[i] = crate::ListHead::<TimerList>::new_head();
|
||||||
}
|
}
|
||||||
self.timer_tick = (self.get_tick_count)();
|
self.timer_tick = (self.get_tick_count)();
|
||||||
/*
|
let cb = Rc::new(
|
||||||
let cb = |e: i32, args: Option<Vec<Rc::<dyn Any>>>| {
|
|e: i32, args: Option<Vec<Rc::<dyn Any>>>| {
|
||||||
};
|
//self.gc_timer(e, args);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
self.set_interval(
|
self.set_interval(
|
||||||
gctime,
|
gctime,
|
||||||
cb
|
cb
|
||||||
);*/
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uninit(&mut self) {
|
pub fn uninit(&mut self) {
|
||||||
@ -102,11 +104,6 @@ impl Timer {
|
|||||||
|
|
||||||
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
|
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
|
||||||
let mut p: 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() {
|
if self.free_timer_list.borrow().empty() {
|
||||||
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
|
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
|
||||||
if Rc::weak_count(&p.borrow().wp) > 0 {
|
if Rc::weak_count(&p.borrow().wp) > 0 {
|
||||||
@ -129,7 +126,7 @@ impl Timer {
|
|||||||
Rc::downgrade(&p.borrow().holder)
|
Rc::downgrade(&p.borrow().holder)
|
||||||
);
|
);
|
||||||
p.borrow_mut().attach_entry = crate::ListHead::<TimerList>::new_head();
|
p.borrow_mut().attach_entry = crate::ListHead::<TimerList>::new_head();
|
||||||
}*/
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +137,7 @@ impl Timer {
|
|||||||
fn internal_add(&mut self,
|
fn internal_add(&mut self,
|
||||||
timer_type: TimerType,
|
timer_type: TimerType,
|
||||||
expire_time: i32,
|
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 {
|
attacher: Option<Rc::<RefCell::<TimerAttacher>>>) -> TimerWp {
|
||||||
let t = self.new_timer_list();
|
let t = self.new_timer_list();
|
||||||
t.borrow_mut().cb = Some(cb);
|
t.borrow_mut().cb = Some(cb);
|
||||||
@ -164,28 +161,28 @@ impl Timer {
|
|||||||
|
|
||||||
pub fn set_timeout(&mut self,
|
pub fn set_timeout(&mut self,
|
||||||
expire_time: i32,
|
expire_time: i32,
|
||||||
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>
|
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>
|
||||||
) -> TimerWp {
|
) -> TimerWp {
|
||||||
return self.internal_add(TimerType::Timeout, expire_time, cb, None);
|
return self.internal_add(TimerType::Timeout, expire_time, cb, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_timeout_ex(&mut self,
|
pub fn set_timeout_ex(&mut self,
|
||||||
expire_time: i32,
|
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 {
|
attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {
|
||||||
return self.internal_add(TimerType::Timeout, expire_time, cb, Some(attacher));
|
return self.internal_add(TimerType::Timeout, expire_time, cb, Some(attacher));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_interval(&mut self,
|
pub fn set_interval(&mut self,
|
||||||
expire_time: i32,
|
expire_time: i32,
|
||||||
cb: Rc::<dyn Fn (i32, Option<Vec<Rc::<dyn Any>>>)>
|
cb: Rc::<dyn FnMut (i32, Option<Vec<Rc::<dyn Any>>>)>
|
||||||
) -> TimerWp {
|
) -> TimerWp {
|
||||||
return self.internal_add(TimerType::Interval, expire_time, cb, None);
|
return self.internal_add(TimerType::Interval, expire_time, cb, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_interval_ex(&mut self,
|
pub fn set_interval_ex(&mut self,
|
||||||
expire_time: i32,
|
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 {
|
attacher: Rc::<RefCell::<TimerAttacher>>) -> TimerWp {
|
||||||
return self.internal_add(TimerType::Interval, expire_time, cb, Some(attacher));
|
return self.internal_add(TimerType::Interval, expire_time, cb, Some(attacher));
|
||||||
}
|
}
|
||||||
@ -219,4 +216,8 @@ impl Timer {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gc_timer(&mut self, e: i32, args: Option<Vec<Rc::<dyn Any>>>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user