Skip to content

Commit

Permalink
disable pool
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Dec 11, 2023
1 parent a4a6243 commit f613d47
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 46 deletions.
21 changes: 0 additions & 21 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
24 changes: 3 additions & 21 deletions src/coroutine_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ impl Done {
name, size, used
);
}

if size == config().get_stack_size() {
get_scheduler().pool.put(co);
}
}
}

Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,7 +182,6 @@ fn steal_local<T>(stealer: &deque::Stealer<T>, local: &deque::Worker<T>) -> Opti

#[repr(align(128))]
pub struct Scheduler {
pub pool: CoroutinePool,
event_loop: EventLoop,
global_queue: dark_std::sync::SyncVec<CoroutineImpl>,
local_queues: Vec<deque::Worker<CoroutineImpl>>,
Expand All @@ -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,
Expand Down

0 comments on commit f613d47

Please sign in to comment.