This commit is contained in:
aozhiwei 2023-10-10 09:18:57 +08:00
parent 1709853ee5
commit 877b9363fd
2 changed files with 30 additions and 20 deletions

View File

@ -32,10 +32,10 @@ impl<T> ListHead<T> {
fn get_rc_refcell(&self) -> Rc::<RefCell::<ListHead<T>>> {
let cell_rc: &Rc<RefCell<ListHead<T>>> = &self.next.upgrade().unwrap();
let head: &ListHead<T> = &*cell_rc.borrow();
//let head: &ListHead<T> = &*cell_rc.borrow();
let cell_start = cell_rc.as_ptr() as *const u8;
let data_start = head as *const ListHead<T> as *const u8;
let cell_offset = unsafe { data_start.offset_from(cell_start) };
//let data_start = head as *const ListHead<T> as *const u8;
//let cell_offset = unsafe { data_start.offset_from(cell_start) };
unsafe {
return Rc::from_raw(cell_start as *const RefCell::<ListHead<T>>);
};

View File

@ -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::<RefCell::<TimerList>>,
wp: Rc::<Rc::<RefCell::<TimerList>>>,
timer_entry: Rc::<RefCell::<crate::ListHead<TimerList>>>,
@ -46,7 +46,7 @@ struct TimerList {
pub struct Timer {
free_timer_num: i32,
free_timer_list: Rc::<RefCell::<crate::ListHead<TimerList>>>,
running_timer: Weak::<RefCell::<TimerList>>,
//running_timer: Weak::<RefCell::<TimerList>>,
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::<RefCell::<TimerList>> {
let mut p: Rc::<RefCell::<TimerList>>;
let p: Rc::<RefCell::<TimerList>>;
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::<RefCell::<crate::ListHead<TimerList>>>;
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<Vec<Rc::<dyn Any>>>) {
_timer_wp: TimerWp,
_e: i32,
_args: Option<Vec<Rc::<dyn Any>>>) {
}
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<Vec<Rc::<dyn Any>>>) {
/*
fn gc_timer(&mut self, _e: i32, _args: Option<Vec<Rc::<dyn Any>>>) {
}
*/
}