This commit is contained in:
aozhiwei 2023-10-28 11:08:13 +08:00
parent 66951e8f78
commit 7eed540867
2 changed files with 16 additions and 17 deletions

View File

@ -53,29 +53,28 @@ impl<T> ListHead<T> {
return self.next.ptr_eq(&self.prev);
}
pub fn add_tail(&self, pnew: &Rc::<RefCell::<Self>>) {
/*
let prev = &mut head.borrow_mut().prev;
let next = Rc::downgrade(head);
pub fn add_tail(&mut self, pnew: &Rc::<RefCell::<Self>>) {
let next = self.shared_from_self();
let prev = &mut self.prev;
next.upgrade().unwrap().borrow_mut().prev = Rc::downgrade(pnew);
pnew.borrow_mut().next = next;
next.borrow_mut().prev = Rc::downgrade(pnew);
pnew.borrow_mut().next = Rc::downgrade(&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>> {
if self.empty() {
panic!("");
}
return self.next.upgrade().unwrap().borrow().data();
}
pub fn replace_init(&self, pnew: &mut Rc::<RefCell::<Self>>) {
/*
pnew.borrow_mut().next = head.borrow_mut().next.clone();
pub fn replace_init(&mut self, pnew: &mut Rc::<RefCell::<Self>>) {
pnew.borrow_mut().next = self.next.clone();
pnew.borrow_mut().next.upgrade().unwrap().borrow_mut().prev = Rc::downgrade(pnew);
pnew.borrow_mut().prev = head.borrow_mut().prev.clone();
head.borrow_mut().init();*/
pnew.borrow_mut().prev = self.prev.clone();
self.init();
}
pub fn for_each(&self, cb: fn (&Weak::<RefCell::<T>>) -> bool) {

View File

@ -211,7 +211,7 @@ impl Timer {
}
if !tv[index].borrow().empty() {
let mut cascade_list = crate::ListHead::<TimerList>::new_head();
tv[index].borrow().replace_init(&mut cascade_list);
tv[index].borrow_mut().replace_init(&mut cascade_list);
while !cascade_list.borrow().empty() {
let timer = &cascade_list.borrow().first_entry().upgrade().unwrap();
timer.borrow_mut().timer_entry.borrow_mut().del_init();
@ -237,7 +237,7 @@ impl Timer {
}
self.timer_tick += 1;
self.work_list.borrow().replace_init(&mut self.tv1[index]);
self.work_list.borrow_mut().replace_init(&mut self.tv1[index]);
while !self.work_list.borrow().empty() {
let timer = &self.work_list.borrow().first_entry();
self.running_timer = timer.clone();
@ -280,7 +280,7 @@ impl Timer {
t.borrow_mut().expires = (self.get_tick_count)() + expire_time as i64;
match attacher {
Some(v) => {
v.borrow_mut().timers.borrow().add_tail(&t.borrow_mut().attach_entry);
v.borrow_mut().timers.borrow_mut().add_tail(&t.borrow_mut().attach_entry);
}
None => {
@ -313,7 +313,7 @@ impl Timer {
index = (t.borrow().expires >> (TVR_BITS + 3 * TVN_BITS)) & (TVN_MASK as i64);
vec = &mut self.tv5[index as usize];
}
vec.borrow().add_tail(&t.borrow_mut().timer_entry);
vec.borrow_mut().add_tail(&t.borrow_mut().timer_entry);
}
fn internal_delete(&mut self, timer_wp: TimerWp, is_destory: bool) {
@ -338,7 +338,7 @@ impl Timer {
if Rc::weak_count(&v.borrow().wp) > 0 {
v.borrow_mut().wp = Rc::new(v.borrow().holder.clone());
}
self.free_timer_list.borrow().add_tail(&v.borrow_mut().timer_entry);
self.free_timer_list.borrow_mut().add_tail(&v.borrow_mut().timer_entry);
self.free_timer_num += 1;
}
None => {