From 1449d290431cbb82d48ccdb8ca2c4169f39c0b6d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 23 Oct 2023 21:38:40 +0800 Subject: [PATCH] 1 --- src/timer.rs | 70 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/timer.rs b/src/timer.rs index 30bbeb0..68f5c46 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -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::::new_head(); + crate::ListHead::::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::>>; - 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::>) { + let idx = t.borrow().expires - self.timer_tick; + let index; + let vec: &mut Rc::>>; + 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) => {