From 877b9363fde9afddd4535a82c79fdf669cbde3b3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 10 Oct 2023 09:18:57 +0800 Subject: [PATCH] 1 --- src/listhead.rs | 6 +++--- src/timer.rs | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/listhead.rs b/src/listhead.rs index e1c3802..6ceccc5 100644 --- a/src/listhead.rs +++ b/src/listhead.rs @@ -32,10 +32,10 @@ impl ListHead { fn get_rc_refcell(&self) -> Rc::>> { let cell_rc: &Rc>> = &self.next.upgrade().unwrap(); - let head: &ListHead = &*cell_rc.borrow(); + //let head: &ListHead = &*cell_rc.borrow(); let cell_start = cell_rc.as_ptr() as *const u8; - let data_start = head as *const ListHead as *const u8; - let cell_offset = unsafe { data_start.offset_from(cell_start) }; + //let data_start = head as *const ListHead as *const u8; + //let cell_offset = unsafe { data_start.offset_from(cell_start) }; unsafe { return Rc::from_raw(cell_start as *const RefCell::>); }; diff --git a/src/timer.rs b/src/timer.rs index e5cf36b..2ed8693 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -2,7 +2,7 @@ use std::rc::{Rc, Weak}; use std::cell::RefCell; use std::any::Any; -const CONFIG_BASE_SMALL: bool = false; +//const CONFIG_BASE_SMALL: bool = false; const TVN_BITS: usize = 6; const TVR_BITS: usize = 8; const TVN_SIZE: usize = 1 << TVN_BITS; @@ -31,7 +31,7 @@ impl Default for TimerType { } #[derive(Default)] -struct TimerList { +pub struct TimerList { holder: Rc::>, wp: Rc::>>, timer_entry: Rc::>>, @@ -46,7 +46,7 @@ struct TimerList { pub struct Timer { free_timer_num: i32, free_timer_list: Rc::>>, - running_timer: Weak::>, + //running_timer: Weak::>, timer_tick: i64, get_tick_count: fn () -> i64, cache_timer_num: i32, @@ -95,7 +95,7 @@ impl Timer { } pub fn uninit(&mut self) { - + self.clear(); } fn clear(&mut self) { @@ -103,7 +103,7 @@ impl Timer { } fn new_timer_list(&mut self) -> Rc::> { - let mut p: Rc::>; + let p: Rc::>; if self.free_timer_list.borrow().empty() { p = self.free_timer_list.borrow().first_entry().upgrade().unwrap(); if Rc::weak_count(&p.borrow().wp) > 0 { @@ -155,7 +155,7 @@ impl Timer { } { let idx = t.borrow().expires - self.timer_tick; - let mut index = 0; + let index; let vec: &mut Rc::>>; if idx < 0 { index = self.timer_tick & (TVR_MASK as i64); @@ -163,9 +163,18 @@ impl Timer { } 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_MASK as i64); - vec = &mut self.tv1[index as usize]; + 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); @@ -202,12 +211,12 @@ impl Timer { } pub fn fire_event(&mut self, - timer_wp: TimerWp, - e: i32, - args: Option>>) { + _timer_wp: TimerWp, + _e: i32, + _args: Option>>) { } - pub fn modify(&mut self, timer_wp: TimerWp, expire_time: i32) { + pub fn modify(&mut self, _timer_wp: TimerWp, _expire_time: i32) { } pub fn delete_current_timer(&mut self) { @@ -216,13 +225,13 @@ impl Timer { pub fn is_running(&self) { } - pub fn delete(&mut self, timer_wp: TimerWp) { + pub fn delete(&mut self, _timer_wp: TimerWp) { } - pub fn reset(&mut self, timer_wp: TimerWp) { + pub fn reset(&mut self, _timer_wp: TimerWp) { } - pub fn get_remain_time(&mut self, timer_wp: TimerWp) -> i64 { + pub fn get_remain_time(&mut self, _timer_wp: TimerWp) -> i64 { return 0; } @@ -230,8 +239,9 @@ impl Timer { return 0; } - fn gc_timer(&mut self, e: i32, args: Option>>) { + /* + fn gc_timer(&mut self, _e: i32, _args: Option>>) { } - + */ }