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;
}
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) {
while (self.get_tick_count)() >= self.timer_tick {
let index = (self.timer_tick & (TVR_MASK as i64)) as usize;
@ -227,35 +244,36 @@ impl Timer {
}
}
{
let idx = t.borrow().expires - self.timer_tick;
let index;
let vec: &mut Rc::<RefCell::<crate::ListHead<TimerList>>>;
if idx < 0 {
index = self.timer_tick & (TVR_MASK as i64);
vec = &mut self.tv1[index as usize];
} else if idx < TVR_SIZE as i64 {
index = t.borrow().expires & (TVR_MASK as i64);
vec = &mut self.tv1[index as usize];
} else if idx < (1 << (TVR_BITS + TVN_BITS)) {
index = (t.borrow().expires >> TVR_BITS) & (TVN_MASK as i64);
vec = &mut self.tv2[index as usize];
} else if idx < (1 << (TVR_BITS + 2 * TVN_BITS)) {
index = (t.borrow().expires >> (TVR_BITS + 1 * TVN_BITS)) & (TVN_MASK as i64);
vec = &mut self.tv3[index as usize];
} else if idx < (1 << (TVR_BITS + 3 * TVN_BITS)) {
index = (t.borrow().expires >> (TVR_BITS + 2 * TVN_BITS)) & (TVN_MASK as i64);
vec = &mut self.tv4[index as usize];
} else {
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);
}
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 index;
let vec: &mut Rc::<RefCell::<crate::ListHead<TimerList>>>;
if idx < 0 {
index = self.timer_tick & (TVR_MASK as i64);
vec = &mut self.tv1[index as usize];
} else if idx < TVR_SIZE as i64 {
index = t.borrow().expires & (TVR_MASK as i64);
vec = &mut self.tv1[index as usize];
} else if idx < (1 << (TVR_BITS + TVN_BITS)) {
index = (t.borrow().expires >> TVR_BITS) & (TVN_MASK as i64);
vec = &mut self.tv2[index as usize];
} else if idx < (1 << (TVR_BITS + 2 * TVN_BITS)) {
index = (t.borrow().expires >> (TVR_BITS + 1 * TVN_BITS)) & (TVN_MASK as i64);
vec = &mut self.tv3[index as usize];
} else if idx < (1 << (TVR_BITS + 3 * TVN_BITS)) {
index = (t.borrow().expires >> (TVR_BITS + 2 * TVN_BITS)) & (TVN_MASK as i64);
vec = &mut self.tv4[index as usize];
} else {
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);
}
fn internal_delete(&mut self, timer_wp: TimerWp, is_destory: bool) {
match timer_wp.upgrade() {
Some(v) => {