From a599356cffbbc1dc4df07a3a43a0f3bcd3415329 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 28 Oct 2023 10:33:36 +0800 Subject: [PATCH] 1 --- src/listhead.rs | 7 ++++--- src/timer.rs | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/listhead.rs b/src/listhead.rs index 6ddd630..df947c6 100644 --- a/src/listhead.rs +++ b/src/listhead.rs @@ -50,18 +50,19 @@ impl ListHead { } pub fn empty(&self) -> bool { - return self as *const ListHead == self.next.upgrade().unwrap().as_ptr(); + return self.next.ptr_eq(&self.prev); } - pub fn add_tail(head: &Rc::>>, + pub fn add_tail(&self, pnew: &Rc::>>) { + /* let prev = &mut head.borrow_mut().prev; let next = Rc::downgrade(head); next.upgrade().unwrap().borrow_mut().prev = Rc::downgrade(pnew); pnew.borrow_mut().next = next; pnew.borrow_mut().prev = prev.clone(); - prev.upgrade().unwrap().borrow_mut().next = Rc::downgrade(pnew); + prev.upgrade().unwrap().borrow_mut().next = Rc::downgrade(pnew);*/ } pub fn first_entry(&self) -> Weak::> { diff --git a/src/timer.rs b/src/timer.rs index e710281..93b454a 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -288,8 +288,7 @@ impl Timer { t.borrow_mut().expires = (self.get_tick_count)() + expire_time as i64; match attacher { Some(v) => { - crate::ListHead::add_tail(&v.borrow_mut().timers, - &t.borrow_mut().attach_entry); + v.borrow_mut().timers.borrow().add_tail(&t.borrow_mut().attach_entry); } None => { @@ -322,7 +321,7 @@ impl Timer { index = (t.borrow().expires >> (TVR_BITS + 3 * TVN_BITS)) & (TVN_MASK as i64); vec = &mut self.tv5[index as usize]; } - crate::ListHead::add_tail(&vec, &t.borrow_mut().timer_entry); + vec.borrow().add_tail(&t.borrow_mut().timer_entry); } fn internal_delete(&mut self, timer_wp: TimerWp, is_destory: bool) { @@ -347,8 +346,7 @@ impl Timer { if Rc::weak_count(&v.borrow().wp) > 0 { v.borrow_mut().wp = Rc::new(v.borrow().holder.clone()); } - crate::ListHead::add_tail(&self.free_timer_list, - &v.borrow_mut().timer_entry); + self.free_timer_list.borrow().add_tail(&v.borrow_mut().timer_entry); self.free_timer_num += 1; } None => {