1
This commit is contained in:
parent
1709853ee5
commit
877b9363fd
@ -32,10 +32,10 @@ impl<T> ListHead<T> {
|
|||||||
|
|
||||||
fn get_rc_refcell(&self) -> Rc::<RefCell::<ListHead<T>>> {
|
fn get_rc_refcell(&self) -> Rc::<RefCell::<ListHead<T>>> {
|
||||||
let cell_rc: &Rc<RefCell<ListHead<T>>> = &self.next.upgrade().unwrap();
|
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 cell_start = cell_rc.as_ptr() as *const u8;
|
||||||
let data_start = head as *const ListHead<T> 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 cell_offset = unsafe { data_start.offset_from(cell_start) };
|
||||||
unsafe {
|
unsafe {
|
||||||
return Rc::from_raw(cell_start as *const RefCell::<ListHead<T>>);
|
return Rc::from_raw(cell_start as *const RefCell::<ListHead<T>>);
|
||||||
};
|
};
|
||||||
|
44
src/timer.rs
44
src/timer.rs
@ -2,7 +2,7 @@ use std::rc::{Rc, Weak};
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
const CONFIG_BASE_SMALL: bool = false;
|
//const CONFIG_BASE_SMALL: bool = false;
|
||||||
const TVN_BITS: usize = 6;
|
const TVN_BITS: usize = 6;
|
||||||
const TVR_BITS: usize = 8;
|
const TVR_BITS: usize = 8;
|
||||||
const TVN_SIZE: usize = 1 << TVN_BITS;
|
const TVN_SIZE: usize = 1 << TVN_BITS;
|
||||||
@ -31,7 +31,7 @@ impl Default for TimerType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TimerList {
|
pub struct TimerList {
|
||||||
holder: Rc::<RefCell::<TimerList>>,
|
holder: Rc::<RefCell::<TimerList>>,
|
||||||
wp: Rc::<Rc::<RefCell::<TimerList>>>,
|
wp: Rc::<Rc::<RefCell::<TimerList>>>,
|
||||||
timer_entry: Rc::<RefCell::<crate::ListHead<TimerList>>>,
|
timer_entry: Rc::<RefCell::<crate::ListHead<TimerList>>>,
|
||||||
@ -46,7 +46,7 @@ struct TimerList {
|
|||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
free_timer_num: i32,
|
free_timer_num: i32,
|
||||||
free_timer_list: Rc::<RefCell::<crate::ListHead<TimerList>>>,
|
free_timer_list: Rc::<RefCell::<crate::ListHead<TimerList>>>,
|
||||||
running_timer: Weak::<RefCell::<TimerList>>,
|
//running_timer: Weak::<RefCell::<TimerList>>,
|
||||||
timer_tick: i64,
|
timer_tick: i64,
|
||||||
get_tick_count: fn () -> i64,
|
get_tick_count: fn () -> i64,
|
||||||
cache_timer_num: i32,
|
cache_timer_num: i32,
|
||||||
@ -95,7 +95,7 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn uninit(&mut self) {
|
pub fn uninit(&mut self) {
|
||||||
|
self.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
@ -103,7 +103,7 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new_timer_list(&mut self) -> Rc::<RefCell::<TimerList>> {
|
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() {
|
if self.free_timer_list.borrow().empty() {
|
||||||
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
|
p = self.free_timer_list.borrow().first_entry().upgrade().unwrap();
|
||||||
if Rc::weak_count(&p.borrow().wp) > 0 {
|
if Rc::weak_count(&p.borrow().wp) > 0 {
|
||||||
@ -155,7 +155,7 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
let idx = t.borrow().expires - self.timer_tick;
|
let idx = t.borrow().expires - self.timer_tick;
|
||||||
let mut index = 0;
|
let index;
|
||||||
let vec: &mut Rc::<RefCell::<crate::ListHead<TimerList>>>;
|
let vec: &mut Rc::<RefCell::<crate::ListHead<TimerList>>>;
|
||||||
if idx < 0 {
|
if idx < 0 {
|
||||||
index = self.timer_tick & (TVR_MASK as i64);
|
index = self.timer_tick & (TVR_MASK as i64);
|
||||||
@ -163,9 +163,18 @@ impl Timer {
|
|||||||
} else if idx < TVR_SIZE as i64 {
|
} else if idx < TVR_SIZE as i64 {
|
||||||
index = t.borrow().expires & (TVR_MASK as i64);
|
index = t.borrow().expires & (TVR_MASK as i64);
|
||||||
vec = &mut self.tv1[index as usize];
|
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 {
|
} else {
|
||||||
index = t.borrow().expires & (TVR_MASK as i64);
|
index = (t.borrow().expires >> (TVR_BITS + 3 * TVN_BITS)) & (TVN_MASK as i64);
|
||||||
vec = &mut self.tv1[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);
|
||||||
@ -202,12 +211,12 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fire_event(&mut self,
|
pub fn fire_event(&mut self,
|
||||||
timer_wp: TimerWp,
|
_timer_wp: TimerWp,
|
||||||
e: i32,
|
_e: i32,
|
||||||
args: Option<Vec<Rc::<dyn Any>>>) {
|
_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) {
|
pub fn delete_current_timer(&mut self) {
|
||||||
@ -216,13 +225,13 @@ impl Timer {
|
|||||||
pub fn is_running(&self) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,8 +239,9 @@ impl Timer {
|
|||||||
return 0;
|
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>>>) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user