This commit is contained in:
aozhiwei 2023-10-07 08:40:55 +08:00
parent 9f8a1d6889
commit a90e99ab62
3 changed files with 42 additions and 14 deletions

View File

@ -1,16 +1,39 @@
pub struct ListHead {
prev: Option<Box<ListHead>>,
next: Option<Box<ListHead>>,
use std::rc::{Rc, Weak};
use std::cell::RefCell;
pub struct ListHead<T> {
prev: Weak::<RefCell::<ListHead<T>>>,
next: Weak::<RefCell::<ListHead<T>>>,
data: Weak::<RefCell::<T>>,
}
impl ListHead {
impl<T> ListHead<T> {
pub fn new() -> Self {
let p = ListHead{
prev: None,
next: None,
};
return p;
pub fn new() -> Rc::<RefCell::<ListHead<T>>> {
let this = Rc::new(RefCell::new(ListHead{
prev: Weak::<RefCell::<ListHead<T>>>::new(),
next: Weak::<RefCell::<ListHead<T>>>::new(),
data: Weak::<RefCell::<T>>::new(),
}));
this.borrow_mut().prev = Rc::downgrade(&this);
this.borrow_mut().next = Rc::downgrade(&this);
return this;
}
pub fn data(&self) -> &Weak::<RefCell::<T>> {
return &self.data;
}
pub fn del(&mut self) {
self.next.upgrade().unwrap().borrow_mut().prev = self.prev.clone();
self.prev.upgrade().unwrap().borrow_mut().next = self.next.clone();
}
pub fn add_tail(&mut self, pnew: &mut ListHead<T>) {
let prev = &mut self.prev;
unsafe {
let next = Weak::from_raw(self);
}
}
}

View File

@ -1,5 +1,5 @@
use std::rc::Rc;
use std::fs::File;
//use std::fs::File;
use std::collections::HashMap;
pub trait ProtoMsg {
@ -91,6 +91,7 @@ impl<T: Clone + ProtoMsg> MetaMgr<T> {
}
pub fn load(&mut self) {
/*
for i in 0..self.meta_classes.len() {
let meta = &self.meta_classes[i];
match File::open(&meta.file_name) {
@ -124,7 +125,7 @@ impl<T: Clone + ProtoMsg> MetaMgr<T> {
}
}
}
}*/
}
pub fn get_metalist(&mut self, idx: i32) -> Option<&Vec::<Rc::<T>>> {

View File

@ -1,17 +1,21 @@
pub struct TimerList {
}
pub struct Timer {
}
impl Timer {
/* pub fn init(&mut self,
pub fn init(&mut self,
get_tick_count: fn () -> i64,
get_fxied_timer_expires: fn (i32, i64) -> i64,
context: (),
gctime: i32,
cache_timer_num: i32) {
}*/
}
pub fn uninit(&mut self) {