1
This commit is contained in:
parent
b7e2fd9e52
commit
28d9f032e2
@ -58,38 +58,10 @@ impl<T> ListHead<T> {
|
||||
let prev = &head.borrow_mut().prev.clone();
|
||||
let next = head;
|
||||
|
||||
/*
|
||||
let a: &Rc::<i32> = &Rc::new(100);
|
||||
let b = Rc::downgrade(a);
|
||||
println!("a:{:p} b:{:p}", Rc::as_ptr(a), b.as_ptr());
|
||||
|
||||
println!("add_tail:{} {} {:p} {:p} {:p} {:p} {:p} {:p} {:p}",
|
||||
head.borrow().empty(),
|
||||
pnew.borrow().empty(),
|
||||
pnew.borrow().next.as_ptr(),
|
||||
pnew.borrow().prev.as_ptr(),
|
||||
Rc::as_ptr(&pnew.borrow().shared_from_self()),
|
||||
Rc::as_ptr(pnew),
|
||||
head.as_ptr(),
|
||||
prev.as_ptr(),
|
||||
next.as_ptr()
|
||||
);
|
||||
*/
|
||||
|
||||
next.borrow_mut().prev = Rc::downgrade(pnew);
|
||||
pnew.borrow_mut().next = Rc::downgrade(&next);
|
||||
pnew.borrow_mut().prev = prev.clone();
|
||||
prev.upgrade().unwrap().borrow_mut().next = Rc::downgrade(pnew);
|
||||
println!("add_tail:{} {} {:p} {:p} {:p} {:p} {:p} {:p}",
|
||||
head.borrow().empty(),
|
||||
pnew.borrow().empty(),
|
||||
pnew.borrow().next.as_ptr(),
|
||||
pnew.borrow().prev.as_ptr(),
|
||||
Rc::as_ptr(pnew),
|
||||
Rc::as_ptr(head),
|
||||
prev.as_ptr(),
|
||||
next.as_ptr()
|
||||
);
|
||||
}
|
||||
|
||||
pub fn first_entry(&self) -> Weak::<RefCell::<T>> {
|
||||
@ -100,22 +72,14 @@ impl<T> ListHead<T> {
|
||||
}
|
||||
|
||||
pub fn replace_init(head: &Rc::<RefCell::<Self>>, pnew: &Rc::<RefCell::<Self>>) {
|
||||
if !head.borrow().empty() {
|
||||
//let timer = &head.borrow().first_entry();
|
||||
//let a = timer.upgrade().unwrap();
|
||||
} else {
|
||||
if head.borrow().empty() {
|
||||
return;
|
||||
}
|
||||
//println!("replace_init");
|
||||
pnew.borrow_mut().next = head.borrow().next.clone();
|
||||
pnew.borrow_mut().next.upgrade().unwrap().borrow_mut().prev = Rc::downgrade(pnew);
|
||||
pnew.borrow_mut().prev = head.borrow().prev.clone();
|
||||
pnew.borrow_mut().prev.upgrade().unwrap().borrow_mut().next = Rc::downgrade(pnew);
|
||||
head.borrow_mut().init();
|
||||
if !pnew.borrow().empty() {
|
||||
//let timer = &pnew.borrow().first_entry();
|
||||
//let a = timer.upgrade().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_each(&self, cb: fn (&Weak::<RefCell::<T>>) -> bool) {
|
||||
|
@ -175,7 +175,6 @@ impl XTimer {
|
||||
p.borrow_mut().wp = Some(Rc::new(p.borrow().holder.clone().unwrap()));
|
||||
}
|
||||
} else {
|
||||
println!("a");
|
||||
p = Rc::new(RefCell::new(TimerList{
|
||||
holder: Default::default(),
|
||||
wp: Default::default(),
|
||||
@ -186,22 +185,17 @@ impl XTimer {
|
||||
expires: 0,
|
||||
cb: None,
|
||||
}));
|
||||
println!("b");
|
||||
{
|
||||
p.borrow_mut().holder = Some(p.clone());
|
||||
}
|
||||
println!("c");
|
||||
{
|
||||
let z = Some(Rc::new(p.borrow().holder.clone().unwrap()));
|
||||
p.borrow_mut().wp = z;
|
||||
}
|
||||
println!("d");
|
||||
p.borrow_mut().timer_entry = crate::ListHead::<TimerList>::new_node(
|
||||
Rc::downgrade(&p)
|
||||
);
|
||||
println!("e");
|
||||
p.borrow_mut().attach_entry = crate::ListHead::<TimerList>::new_head();
|
||||
println!("f");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@ -226,7 +220,6 @@ impl XTimer {
|
||||
tv = &self.tv5;
|
||||
}
|
||||
}
|
||||
println!("zzzzzzz idx:{} index:{}", idx, index);
|
||||
if !tv[index].borrow().empty() {
|
||||
let cascade_list = crate::ListHead::<TimerList>::new_head();
|
||||
crate::ListHead::<TimerList>::replace_init
|
||||
@ -309,55 +302,6 @@ impl XTimer {
|
||||
this.borrow_mut().running_timer = Weak::new();
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn update(&mut self) {
|
||||
let tick = (*self.get_tick_count.as_ref().unwrap())();
|
||||
while tick >= self.timer_tick {
|
||||
let index = (self.timer_tick & (TVR_MASK as i64)) as usize;
|
||||
if index == 0 &&
|
||||
self.cascade(0) == 0 &&
|
||||
self.cascade(1) == 0 &&
|
||||
self.cascade(2) == 0 {
|
||||
self.cascade(3);
|
||||
}
|
||||
self.timer_tick += 1;
|
||||
|
||||
//println!("timer_tick:{} index:{} empty:{}", self.timer_tick, index, self.tv1[index].borrow().empty());
|
||||
crate::ListHead::<TimerList>::replace_init
|
||||
(&self.tv1[index],
|
||||
&self.work_list);
|
||||
while !self.work_list.borrow().empty() {
|
||||
let timer = &self.work_list.borrow().first_entry();
|
||||
self.running_timer = timer.clone();
|
||||
//let a = timer.upgrade().unwrap();
|
||||
match &mut timer.upgrade().unwrap().borrow_mut().cb {
|
||||
Some(v) => {
|
||||
(*v)(TimerEvent::Exec, None);
|
||||
}
|
||||
None => {
|
||||
}
|
||||
}
|
||||
println!("timer_tick2:{}", self.timer_tick);
|
||||
match self.running_timer.upgrade() {
|
||||
Some(v) => {
|
||||
match v.borrow().timer_type {
|
||||
TimerType::Timeout => {
|
||||
self.internal_delete(Rc::downgrade(&v.borrow().wp.clone().unwrap()), false);
|
||||
}
|
||||
TimerType::Interval => {
|
||||
self.modify(Rc::downgrade(&v.borrow().wp.clone().unwrap()),
|
||||
v.borrow().expire_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.running_timer = Weak::new();
|
||||
}*/
|
||||
|
||||
fn internal_add(&mut self,
|
||||
timer_type: TimerType,
|
||||
expire_time: i32,
|
||||
|
Loading…
x
Reference in New Issue
Block a user