From aff0907a6b979eca11fef12c45c10df1a4b581f0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 10 Oct 2023 08:32:46 +0800 Subject: [PATCH] 1 --- src/timer.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/timer.rs b/src/timer.rs index aa81036..9b971cc 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -40,7 +40,7 @@ struct TimerList { expire_time: i32, expires: i64, - cb: Option>>)>>, + cb: Option>>)>>, } pub struct Timer { @@ -82,14 +82,16 @@ impl Timer { self.tv5[i] = crate::ListHead::::new_head(); } self.timer_tick = (self.get_tick_count)(); - /* - let cb = |e: i32, args: Option>>| { - }; + let cb = Rc::new( + |e: i32, args: Option>>| { + //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::> { let mut p: Rc::>; - 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::::new_head(); - }*/ + } return p; } @@ -140,7 +137,7 @@ impl Timer { fn internal_add(&mut self, timer_type: TimerType, expire_time: i32, - cb: Rc::>>)>, + cb: Rc::>>)>, attacher: Option>>) -> 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::>>)> + cb: Rc::>>)> ) -> TimerWp { return self.internal_add(TimerType::Timeout, expire_time, cb, None); } pub fn set_timeout_ex(&mut self, expire_time: i32, - cb: Rc::>>)>, + cb: Rc::>>)>, attacher: Rc::>) -> TimerWp { return self.internal_add(TimerType::Timeout, expire_time, cb, Some(attacher)); } pub fn set_interval(&mut self, expire_time: i32, - cb: Rc::>>)> + cb: Rc::>>)> ) -> TimerWp { return self.internal_add(TimerType::Interval, expire_time, cb, None); } pub fn set_interval_ex(&mut self, expire_time: i32, - cb: Rc::>>)>, + cb: Rc::>>)>, attacher: Rc::>) -> 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>>) { + + } + }