This commit is contained in:
aozhiwei 2023-10-28 10:33:36 +08:00
parent 8b68ed92b6
commit a599356cff
2 changed files with 7 additions and 8 deletions

View File

@ -50,18 +50,19 @@ impl<T> ListHead<T> {
}
pub fn empty(&self) -> bool {
return self as *const ListHead<T> == self.next.upgrade().unwrap().as_ptr();
return self.next.ptr_eq(&self.prev);
}
pub fn add_tail(head: &Rc::<RefCell::<ListHead<T>>>,
pub fn add_tail(&self,
pnew: &Rc::<RefCell::<ListHead<T>>>) {
/*
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::<RefCell::<T>> {

View File

@ -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 => {