1
This commit is contained in:
parent
cbca2a666f
commit
c950f6d288
@ -58,7 +58,7 @@ pub struct App {
|
||||
zone_id: i32,
|
||||
node_id: i32,
|
||||
instance_id: i32,
|
||||
tokio_rt: Runtime,
|
||||
//tokio_rt: Runtime,
|
||||
user_app: Option<Rc::<RefCell::<dyn UserApp>>>,
|
||||
im_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
|
||||
im_work_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
|
||||
@ -134,7 +134,7 @@ impl App {
|
||||
zone_id: 0,
|
||||
node_id: 0,
|
||||
instance_id: 0,
|
||||
tokio_rt: Runtime::new().unwrap(),
|
||||
//tokio_rt: Runtime::new().unwrap(),
|
||||
user_app: None,
|
||||
im_msgs: r9::ListHead::<IMMsgNode>::new_head(),
|
||||
im_work_msgs: r9::ListHead::<IMMsgNode>::new_head(),
|
||||
@ -158,7 +158,7 @@ impl App {
|
||||
|
||||
pub fn init(user_app: Rc::<RefCell::<dyn UserApp>>) {
|
||||
App::instance().borrow_mut().user_app = Some(user_app.clone());
|
||||
App::instance().borrow_mut().tokio_rt.enter();
|
||||
//App::instance().borrow_mut().tokio_rt.enter();
|
||||
//App::instance().borrow_mut().init_http_server();
|
||||
crate::Timer::instance().borrow_mut().init();
|
||||
user_app.borrow_mut().init();
|
||||
|
@ -1,44 +1,52 @@
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::thread::Thread;
|
||||
use r9_macro::SharedFromSelf;
|
||||
use r9_macro_derive::SharedFromSelf;
|
||||
use std::default::Default;
|
||||
|
||||
#[derive(SharedFromSelf)]
|
||||
pub struct Queue<T> {
|
||||
msg_list: Mutex<Rc::<RefCell::<crate::ListHead<T>>>>,
|
||||
pub work_list: Rc::<RefCell::<crate::ListHead<T>>>,
|
||||
_self_wp: Weak::<RefCell::<Self>>,
|
||||
pub work_list: Mutex<Rc::<RefCell::<crate::ListHead<T>>>>,
|
||||
}
|
||||
|
||||
unsafe impl<T> Send for Queue<T> {}
|
||||
unsafe impl<T> Sync for Queue<T> {}
|
||||
|
||||
impl<T> Queue<T> {
|
||||
|
||||
pub fn new() -> Rc::<RefCell::<Self>> {
|
||||
let this = Rc::new(RefCell::new(Self{
|
||||
msg_list: Mutex::new(crate::ListHead::<T>::new_head()),
|
||||
work_list: crate::ListHead::<T>::new_head(),
|
||||
_self_wp: Default::default(),
|
||||
work_list: Mutex::new(crate::ListHead::<T>::new_head()),
|
||||
}));
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn new_ex() -> Arc::<Mutex::<Self>> {
|
||||
let this = Arc::new(Mutex::new(Self{
|
||||
msg_list: Mutex::new(crate::ListHead::<T>::new_head()),
|
||||
work_list: Mutex::new(crate::ListHead::<T>::new_head()),
|
||||
}));
|
||||
this.borrow_mut()._self_wp = Rc::downgrade(&this);
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn push(&self, node: &Rc::<RefCell::<crate::ListHead<T>>>) {
|
||||
println!("Child thread ID is: {:?}", thread::current().id());
|
||||
crate::ListHead::<T>::add_tail(&self.msg_list.lock().unwrap(), node);
|
||||
}
|
||||
|
||||
pub fn fetch(&self) {
|
||||
if !self.msg_list.lock().unwrap().borrow().empty() &&
|
||||
self.work_list.borrow().empty() {
|
||||
crate::ListHead::replace_init(&self.work_list, &self.msg_list.lock().unwrap());
|
||||
self.work_list.lock().unwrap().borrow().empty() {
|
||||
crate::ListHead::replace_init(&self.msg_list.lock().unwrap(), &self.work_list.lock().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn empty(&self) -> bool {
|
||||
if !self.work_list.borrow().empty() {
|
||||
if !self.work_list.lock().unwrap().borrow().empty() {
|
||||
return false
|
||||
}
|
||||
return self.msg_list.lock().unwrap().borrow().empty()
|
||||
|
Loading…
x
Reference in New Issue
Block a user