Trait open_coroutine_core::scheduler::Scheduler
source · pub trait Scheduler<'s, Join: JoinHandle<Self>>: Debug + Default + Named + Current<'s> + Listener {
// Required methods
fn get_stack_size(&self) -> usize;
fn set_stack_size(&self, stack_size: usize);
fn submit_raw_co(
&self,
coroutine: SchedulableCoroutine<'static>
) -> Result<()>;
fn try_resume(&self, co_name: &str) -> Result<()>;
fn try_timeout_schedule(&self, timeout_time: u64) -> Result<u64>;
fn try_get_co_result(
&self,
co_name: &str
) -> Option<Result<Option<usize>, &'s str>>;
fn size(&self) -> usize;
fn add_listener(&mut self, listener: impl Listener + 's);
// Provided methods
fn submit_co(
&self,
f: impl FnOnce(&dyn Suspender<'_, Resume = (), Yield = ()>, ()) -> Option<usize> + UnwindSafe + 'static,
stack_size: Option<usize>
) -> Result<Join> { ... }
fn try_schedule(&self) -> Result<()> { ... }
fn try_timed_schedule(&self, dur: Duration) -> Result<u64> { ... }
fn is_empty(&self) -> bool { ... }
}
Expand description
A trait implemented for schedulers.
Required Methods§
sourcefn get_stack_size(&self) -> usize
fn get_stack_size(&self) -> usize
Get the default stack stack size for the coroutines in this scheduler.
If it has not been set, it will be crate::constant::DEFAULT_STACK_SIZE
.
sourcefn set_stack_size(&self, stack_size: usize)
fn set_stack_size(&self, stack_size: usize)
Set the default stack stack size for the coroutines in this scheduler.
If it has not been set, it will be crate::constant::DEFAULT_STACK_SIZE
.
sourcefn submit_raw_co(&self, coroutine: SchedulableCoroutine<'static>) -> Result<()>
fn submit_raw_co(&self, coroutine: SchedulableCoroutine<'static>) -> Result<()>
Submit a closure to create new coroutine, then the coroutine will be push into ready queue.
Allow multiple threads to concurrently submit coroutine to the scheduler, but only allow one thread to execute scheduling.
sourcefn try_resume(&self, co_name: &str) -> Result<()>
fn try_resume(&self, co_name: &str) -> Result<()>
Resume a coroutine from the system call table to the ready queue, it’s generally only required for framework level crates.
If we can’t find the coroutine, nothing happens.
Errors
if change to ready fails.
sourcefn try_timeout_schedule(&self, timeout_time: u64) -> Result<u64>
fn try_timeout_schedule(&self, timeout_time: u64) -> Result<u64>
Attempt to schedule the coroutines before the timeout_time
timestamp.
Allow multiple threads to concurrently submit coroutine to the scheduler, but only allow one thread to execute scheduling.
Returns the left time in ns.
Errors
if change to ready fails.
sourcefn try_get_co_result(
&self,
co_name: &str
) -> Option<Result<Option<usize>, &'s str>>
fn try_get_co_result( &self, co_name: &str ) -> Option<Result<Option<usize>, &'s str>>
Attempt to obtain coroutine result with the given co_name
.
sourcefn add_listener(&mut self, listener: impl Listener + 's)
fn add_listener(&mut self, listener: impl Listener + 's)
Add a listener to this scheduler.
Provided Methods§
sourcefn submit_co(
&self,
f: impl FnOnce(&dyn Suspender<'_, Resume = (), Yield = ()>, ()) -> Option<usize> + UnwindSafe + 'static,
stack_size: Option<usize>
) -> Result<Join>
fn submit_co( &self, f: impl FnOnce(&dyn Suspender<'_, Resume = (), Yield = ()>, ()) -> Option<usize> + UnwindSafe + 'static, stack_size: Option<usize> ) -> Result<Join>
Submit a closure to create new coroutine, then the coroutine will be push into ready queue.
Allow multiple threads to concurrently submit coroutine to the scheduler, but only allow one thread to execute scheduling.
Errors
if create coroutine fails.
sourcefn try_schedule(&self) -> Result<()>
fn try_schedule(&self) -> Result<()>
Schedule the coroutines.
Allow multiple threads to concurrently submit coroutine to the scheduler, but only allow one thread to execute scheduling.
Errors
see try_timeout_schedule
.