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>
impl<S: 'static> OwnedTasks<S>
pub(crate) fn new(num_cores: usize) -> Self
sourcepub(crate) fn bind<T>(
&self,
task: T,
scheduler: S,
id: Id,
) -> (JoinHandle<T::Output>, Option<Notified<S>>)
pub(crate) fn bind<T>( &self, task: T, scheduler: S, id: Id, ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
Binds the provided task to this OwnedTasks
instance. This fails if the
OwnedTasks
has been closed.
sourcepub(crate) unsafe fn bind_local<T>(
&self,
task: T,
scheduler: S,
id: Id,
) -> (JoinHandle<T::Output>, Option<Notified<S>>)
pub(crate) unsafe fn bind_local<T>( &self, task: T, scheduler: S, id: Id, ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
Bind a task that isn’t safe to transfer across thread boundaries.
§Safety
Only use this in LocalRuntime
where the task cannot move
sourceunsafe fn bind_inner(
&self,
task: Task<S>,
notified: Notified<S>,
) -> Option<Notified<S>>where
S: Schedule,
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.
sourcepub(crate) fn assert_owner(&self, task: Notified<S>) -> LocalNotified<S>
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.
sourcepub(crate) fn close_and_shutdown_all(&self, start: usize)where
S: Schedule,
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.
pub(crate) fn get_shard_size(&self) -> usize
pub(crate) fn num_alive_tasks(&self) -> usize
pub(crate) fn spawned_tasks_count(&self) -> u64
pub(crate) fn remove(&self, task: &Task<S>) -> Option<Task<S>>
pub(crate) fn is_empty(&self) -> bool
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
.