#[repr(C)]pub struct Scheduler<'s> { /* private fields */ }
Expand description
The scheduler impls.
Implementations§
Source§impl<'s> Scheduler<'s>
impl<'s> Scheduler<'s>
Sourcepub fn stack_size(&self) -> usize
pub fn stack_size(&self) -> usize
Get the default stack size for the coroutines in this scheduler.
If it has not been set, it will be crate::common::constants::DEFAULT_STACK_SIZE
.
Sourcepub fn submit_co(
&self,
f: impl FnOnce(&Suspender<'_, (), ()>, ()) -> Option<usize> + 'static,
stack_size: Option<usize>,
priority: Option<c_longlong>,
) -> Result<String>
pub fn submit_co( &self, f: impl FnOnce(&Suspender<'_, (), ()>, ()) -> Option<usize> + 'static, stack_size: Option<usize>, priority: Option<c_longlong>, ) -> Result<String>
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.
Sourcepub fn add_listener(&mut self, listener: impl Listener<(), Option<usize>> + 's)
pub fn add_listener(&mut self, listener: impl Listener<(), Option<usize>> + 's)
Add a listener to this scheduler.
Sourcepub fn submit_raw_co(&self, co: SchedulableCoroutine<'s>) -> Result<String>
pub fn submit_raw_co(&self, co: SchedulableCoroutine<'s>) -> Result<String>
Submit a raw 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.
Sourcepub fn try_resume(&self, co_name: &'s str)
pub fn try_resume(&self, co_name: &'s str)
Resume a coroutine from the syscall 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.
Sourcepub fn try_schedule(
&mut self,
) -> Result<HashMap<&str, Result<Option<usize>, &str>>>
pub fn try_schedule( &mut self, ) -> Result<HashMap<&str, Result<Option<usize>, &str>>>
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
.
Sourcepub fn try_timed_schedule(
&mut self,
dur: Duration,
) -> Result<(u64, HashMap<&str, Result<Option<usize>, &str>>)>
pub fn try_timed_schedule( &mut self, dur: Duration, ) -> Result<(u64, HashMap<&str, Result<Option<usize>, &str>>)>
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
.
Sourcepub fn try_timeout_schedule(
&mut self,
timeout_time: u64,
) -> Result<(u64, HashMap<&str, Result<Option<usize>, &str>>)>
pub fn try_timeout_schedule( &mut self, timeout_time: u64, ) -> Result<(u64, HashMap<&str, Result<Option<usize>, &str>>)>
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 schedule.
Returns the left time in ns.
§Errors
if change to ready fails.
Sourcepub fn try_cancel_coroutine(co_name: &str)
pub fn try_cancel_coroutine(co_name: &str)
Cancel the coroutine by name.
Sourcepub fn get_scheduling_thread(co_name: &str) -> Option<Pthread>
pub fn get_scheduling_thread(co_name: &str) -> Option<Pthread>
Get the scheduling thread of the coroutine.