From 60265ba68de76553aa0797fb8b21590cc8c130a2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 8 Oct 2023 09:03:07 +0800 Subject: [PATCH] 1 --- src/timer.rs | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/timer.rs b/src/timer.rs index b113af6..944b893 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -27,7 +27,7 @@ struct TimerList { expire_time: i32, expires: i64, - //cb: fn (i32, Option>>), + cb: Option>>)>, } pub struct Timer { @@ -76,16 +76,24 @@ impl Timer { } fn new_timer_list(&mut self) -> Rc::> { - let p = Rc::new(RefCell::new(TimerList{ - holder: Default::default(), - wp: Default::default(), - timer_entry: Default::default(), - attach_entry: Default::default(), - timer_type: 0, - expire_time: 0, - expires: 0, - //cb: Default::default(), - })); + let mut p: Rc::>; + 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 { + p.borrow_mut().wp = Rc::new(p.borrow().holder.clone()); + } + } else { + p = Rc::new(RefCell::new(TimerList{ + holder: Default::default(), + wp: Default::default(), + timer_entry: Default::default(), + attach_entry: Default::default(), + timer_type: 0, + expire_time: 0, + expires: 0, + cb: None, + })); + } return p; } @@ -95,27 +103,14 @@ impl Timer { pub fn set_timeout(&mut self, expire_time: i32, - cb: fn (i32, Option>>)) { - + cb: fn (i32, Option>>)) -> TimerWp { + return TimerWp::new(); } pub fn set_timeout_ex(&mut self, expire_time: i32, cb: fn (i32, Option>>), - attacher: Rc::>) { - - } - - pub fn set_timeout_wp(&mut self, - expire_time: i32, - cb: fn (i32, Option>>)) -> TimerWp { - return TimerWp::new(); - } - - pub fn set_timeout_wp_ex(&mut self, - expire_time: i32, - cb: fn (i32, Option>>), - attacher: Rc::>) -> TimerWp { + attacher: Rc::>) -> TimerWp { return TimerWp::new(); }