From c950f6d2883a3213a17d514eded9fdcc86f400b5 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 11 May 2024 08:27:29 +0800 Subject: [PATCH] 1 --- f9/src/app.rs | 6 +++--- r9/src/queue.rs | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/f9/src/app.rs b/f9/src/app.rs index 2c38605..874814b 100644 --- a/f9/src/app.rs +++ b/f9/src/app.rs @@ -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>>, im_msgs: Rc::>>, im_work_msgs: Rc::>>, @@ -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::::new_head(), im_work_msgs: r9::ListHead::::new_head(), @@ -158,7 +158,7 @@ impl App { pub fn init(user_app: Rc::>) { 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(); diff --git a/r9/src/queue.rs b/r9/src/queue.rs index 01c3da3..468103d 100644 --- a/r9/src/queue.rs +++ b/r9/src/queue.rs @@ -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 { msg_list: Mutex>>>, - pub work_list: Rc::>>, - _self_wp: Weak::>, + pub work_list: Mutex>>>, } +unsafe impl Send for Queue {} +unsafe impl Sync for Queue {} + impl Queue { pub fn new() -> Rc::> { let this = Rc::new(RefCell::new(Self{ msg_list: Mutex::new(crate::ListHead::::new_head()), - work_list: crate::ListHead::::new_head(), - _self_wp: Default::default(), + work_list: Mutex::new(crate::ListHead::::new_head()), + })); + return this; + } + + pub fn new_ex() -> Arc::> { + let this = Arc::new(Mutex::new(Self{ + msg_list: Mutex::new(crate::ListHead::::new_head()), + work_list: Mutex::new(crate::ListHead::::new_head()), })); - this.borrow_mut()._self_wp = Rc::downgrade(&this); return this; } pub fn push(&self, node: &Rc::>>) { - println!("Child thread ID is: {:?}", thread::current().id()); crate::ListHead::::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()