Struct tokio::runtime::task::list::OwnedTasks

source ·
pub(crate) struct OwnedTasks<S: 'static> {
    list: ShardedList<Task<S>, <Task<S> as Link>::Target>,
    pub(crate) id: NonZeroU64,
    closed: AtomicBool,
}

Fields§

§list: ShardedList<Task<S>, <Task<S> as Link>::Target>§id: NonZeroU64§closed: AtomicBool

Implementations§

source§

impl<S: 'static> OwnedTasks<S>

source

pub(crate) fn new(num_cores: usize) -> Self

source

pub(crate) fn bind<T>( &self, task: T, scheduler: S, id: Id, ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
where S: Schedule, T: Future + Send + 'static, T::Output: Send + 'static,

Binds the provided task to this OwnedTasks instance. This fails if the OwnedTasks has been closed.

source

pub(crate) unsafe fn bind_local<T>( &self, task: T, scheduler: S, id: Id, ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
where S: Schedule, T: Future + 'static, T::Output: 'static,

Bind a task that isn’t safe to transfer across thread boundaries.

§Safety

Only use this in LocalRuntime where the task cannot move

source

unsafe fn bind_inner( &self, task: Task<S>, notified: Notified<S>, ) -> Option<Notified<S>>
where S: Schedule,

The part of bind that’s the same for every type of future.

source

pub(crate) fn assert_owner(&self, task: Notified<S>) -> LocalNotified<S>

Asserts that the given task is owned by this OwnedTasks and convert it to a LocalNotified, giving the thread permission to poll this task.

source

pub(crate) fn close_and_shutdown_all(&self, start: usize)
where S: Schedule,

Shuts down all tasks in the collection. This call also closes the collection, preventing new items from being added.

The parameter start determines which shard this method will start at. Using different values for each worker thread reduces contention.

source

pub(crate) fn get_shard_size(&self) -> usize

source

pub(crate) fn num_alive_tasks(&self) -> usize

source

pub(crate) fn spawned_tasks_count(&self) -> u64

source

pub(crate) fn remove(&self, task: &Task<S>) -> Option<Task<S>>

source

pub(crate) fn is_empty(&self) -> bool

source

fn gen_shared_list_size(num_cores: usize) -> usize

Generates the size of the sharded list based on the number of worker threads.

The sharded lock design can effectively alleviate lock contention performance problems caused by high concurrency.

However, as the number of shards increases, the memory continuity between nodes in the intrusive linked list will diminish. Furthermore, the construction time of the sharded list will also increase with a higher number of shards.

Due to the above reasons, we set a maximum value for the shared list size, denoted as MAX_SHARED_LIST_SIZE.

Auto Trait Implementations§

§

impl<S> !Freeze for OwnedTasks<S>

§

impl<S> RefUnwindSafe for OwnedTasks<S>

§

impl<S> Send for OwnedTasks<S>

§

impl<S> Sync for OwnedTasks<S>

§

impl<S> Unpin for OwnedTasks<S>

§

impl<S> UnwindSafe for OwnedTasks<S>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.