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§

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

fn size(&self) -> usize

Returns the number of coroutines owned by this scheduler.

source

fn add_listener(&mut self, listener: impl Listener + 's)

Add a listener to this scheduler.

Provided Methods§

source

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.

source

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.

source

fn try_timed_schedule(&self, dur: Duration) -> Result<u64>

Try scheduling the coroutines for up to dur.

Allow multiple threads to concurrently submit coroutine to the scheduler, but only allow one thread to execute scheduling.

Errors

see try_timeout_schedule.

source

fn is_empty(&self) -> bool

Returns true if the ready queue, suspend queue, and syscall queue are all empty.

Object Safety§

This trait is not object safe.

Implementors§