diff --git a/src/config.rs b/src/config.rs index 4e19032..0ddb4f1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,11 +6,9 @@ use std::sync::atomic::{AtomicUsize, Ordering}; // default stack size, in usize // windows has a minimal size as 0x4a8!!!! const DEFAULT_STACK_SIZE: usize = 6 * 1024 * 1024; -const DEFAULT_POOL_CAPACITY: usize = 100; static WORKERS: AtomicUsize = AtomicUsize::new(0); static STACK_SIZE: AtomicUsize = AtomicUsize::new(DEFAULT_STACK_SIZE); -static POOL_CAPACITY: AtomicUsize = AtomicUsize::new(DEFAULT_POOL_CAPACITY); /// `mco` Configuration type pub struct Config; @@ -46,25 +44,6 @@ impl Config { } } - /// set cached coroutine pool number - /// - /// if you pass 0 to it, will use internal default - pub fn set_pool_capacity(&self, capacity: usize) -> &Self { - info!("set pool capacity={:?}", capacity); - POOL_CAPACITY.store(capacity, Ordering::Release); - self - } - - /// get the coroutine pool capacity - pub fn get_pool_capacity(&self) -> usize { - let size = POOL_CAPACITY.load(Ordering::Acquire); - if size != 0 { - size - } else { - DEFAULT_POOL_CAPACITY - } - } - /// set default coroutine stack size in usize /// /// if you pass 0 to it, will use internal default diff --git a/src/coroutine_impl.rs b/src/coroutine_impl.rs index 6592428..1ed5b80 100644 --- a/src/coroutine_impl.rs +++ b/src/coroutine_impl.rs @@ -78,10 +78,6 @@ impl Done { name, size, used ); } - - if size == config().get_stack_size() { - get_scheduler().pool.put(co); - } } } @@ -296,15 +292,7 @@ impl Builder { { static DONE: Done = Done {}; - let sched = get_scheduler(); let stack_size = self.stack_size.unwrap_or_else(|| config().get_stack_size()); - let _co = if stack_size == config().get_stack_size() { - let co = sched.pool.get(); - co.prefetch(); - Some(co) - } else { - None - }; // create a join resource, shared by waited coroutine and *this* coroutine let panic = Arc::new(AtomicCell::new(None)); @@ -330,15 +318,9 @@ impl Builder { subscriber }; - let mut co = if let Some(mut c) = _co { - // re-init the closure - c.init_code(closure); - c - } else { - CoroutineImpl { - worker_thread_id: None, - inner: Gn::new_opt(stack_size, closure), - } + let mut co = CoroutineImpl { + worker_thread_id: None, + inner: Gn::new_opt(stack_size, closure), }; let handle = Coroutine::new(self.name, stack_size); diff --git a/src/pool.rs b/src/pool.rs index b3b9778..b2b828a 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -21,7 +21,7 @@ impl CoroutinePool { } pub fn new() -> Self { - let capacity = config().get_pool_capacity(); + let capacity = 100; let pool = Queue::new(capacity); for _ in 0..capacity { let co = Self::create_dummy_coroutine(); diff --git a/src/scheduler.rs b/src/scheduler.rs index a2b6c79..62e5dd9 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -7,7 +7,6 @@ use std::time::Duration; use crate::config::config; use crate::coroutine_impl::{run_coroutine, CoroutineImpl}; use crate::io::{EventLoop, Selector}; -use crate::pool::CoroutinePool; use crate::std::sync::AtomicOption; use crate::timeout_list; use crate::yield_now::set_co_para; @@ -183,7 +182,6 @@ fn steal_local(stealer: &deque::Stealer, local: &deque::Worker) -> Opti #[repr(align(128))] pub struct Scheduler { - pub pool: CoroutinePool, event_loop: EventLoop, global_queue: dark_std::sync::SyncVec, local_queues: Vec>, @@ -210,7 +208,6 @@ impl Scheduler { stealers.push(stealers_l); } Box::new(Scheduler { - pool: CoroutinePool::new(), event_loop: EventLoop::new(workers).expect("can't create event_loop"), global_queue: dark_std::sync::SyncVec::new(), local_queues,