This commit is contained in:
aozhiwei 2023-10-23 21:38:40 +08:00
parent 90f5d9f291
commit 1449d29043

View File

@ -167,6 +167,23 @@ impl Timer {
return p; return p;
} }
fn cascade(&mut self, tv: &mut [TimerListListHeadRp], index: usize) -> usize {
if !tv[index].borrow().empty() {
let mut cascade_list = crate::ListHead::<TimerList>::new_head();
crate::ListHead::<TimerList>::replace_init
(
&mut tv[index],
&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();
}
}
return 0;
}
pub fn update(&mut self) { pub fn update(&mut self) {
while (self.get_tick_count)() >= self.timer_tick { while (self.get_tick_count)() >= self.timer_tick {
let index = (self.timer_tick & (TVR_MASK as i64)) as usize; let index = (self.timer_tick & (TVR_MASK as i64)) as usize;
@ -227,7 +244,11 @@ impl Timer {
} }
} }
{ self.internal_add2(&t);
return Rc::downgrade(&t.borrow().wp);
}
fn internal_add2(&mut self, t: &Rc::<RefCell::<TimerList>>) {
let idx = t.borrow().expires - self.timer_tick; let idx = t.borrow().expires - self.timer_tick;
let index; let index;
let vec: &mut Rc::<RefCell::<crate::ListHead<TimerList>>>; let vec: &mut Rc::<RefCell::<crate::ListHead<TimerList>>>;
@ -250,10 +271,7 @@ impl Timer {
index = (t.borrow().expires >> (TVR_BITS + 3 * TVN_BITS)) & (TVN_MASK as i64); index = (t.borrow().expires >> (TVR_BITS + 3 * TVN_BITS)) & (TVN_MASK as i64);
vec = &mut self.tv5[index as usize]; vec = &mut self.tv5[index as usize];
} }
crate::ListHead::add_tail(&vec, crate::ListHead::add_tail(&vec, &t.borrow_mut().timer_entry);
&t.borrow_mut().timer_entry);
}
return Rc::downgrade(&t.borrow().wp);
} }
fn internal_delete(&mut self, timer_wp: TimerWp, is_destory: bool) { fn internal_delete(&mut self, timer_wp: TimerWp, is_destory: bool) {