Repository: tokio-rs/tokio
File: tokio/src/runtime/task/list.rs (Rust)

Code before:
    _not_send_or_sync: PhantomData<*const ()>,
}

struct OwnedTasksInner<S: 'static> {
    list: LinkedList<Task<S>, <Task<S> as Link>::Target>,
    closed: bool,
}

impl<S: 'static> OwnedTasks<S> {
    pub(crate) fn new(num_cores: usize) -> Self {
        let shard_size = Self::gen_shared_list_size(num_cores);
        Self {
            list: List::new(shard_size),
            closed: AtomicBool::new(false),
            id: get_next_id(),
        }
    }

    /// Binds the provided task to this `OwnedTasks` instance. This fails if the
    /// `OwnedTasks` has been closed.
    pub(crate) fn bind<T>(
        &self,
        task: T,
        scheduler: S,
        id: super::Id,
        #[cfg(tokio_unstable)] spawned_at: &'static Location<'static>,
    ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
    where
        S: Schedule,
        T: Future + Send + 'static,
        T::Output: Send + 'static,
    {
        let (task, notified, join) = super::new_task(
            task,
            scheduler,
            id,
            #[cfg(tokio_unstable)]
            spawned_at,
        );
        let notified = unsafe { self.bind_inner(task, notified) };
        (join, notified)
    }

    /// Bind a task that isn't safe to transfer across thread boundaries.
    ///
    /// # Safety
    /// Only use this in `LocalRuntime` where the task cannot move
    pub(crate) unsafe fn bind_local<T>(
        &self,
        task: T,
        scheduler: S,

Review comment (refactor):
Not a blocker.

Let `cfg` modify the parameter list is not a common pattern in Rust, I think we need to explore a better approach.

I don't think this issue blocks this PR, we could open another PR to simplify the implementation.

Code after:

struct OwnedTasksInner<S: 'static> {
    list: LinkedList<Task<S>, <Task<S> as Link>::Target>,
    closed: bool,
}

impl<S: 'static> OwnedTasks<S> {
    pub(crate) fn new(num_cores: usize) -> Self {
        let shard_size = Self::gen_shared_list_size(num_cores);
        Self {
            list: List::new(shard_size),
            closed: AtomicBool::new(false),
            id: get_next_id(),
        }
    }

    /// Binds the provided task to this `OwnedTasks` instance. This fails if the
    /// `OwnedTasks` has been closed.
    pub(crate) fn bind<T>(
        &self,
        task: T,
        scheduler: S,
        id: super::Id,
        spawned_at: SpawnLocation,
    ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
    where
        S: Schedule,
        T: Future + Send + 'static,
        T::Output: Send + 'static,
    {
        let (task, notified, join) = super::new_task(task, scheduler, id, spawned_at);
        let notified = unsafe { self.bind_inner(task, notified) };
        (join, notified)
    }

    /// Bind a task that isn't safe to transfer across thread boundaries.
    ///
    /// # Safety
    /// Only use this in `LocalRuntime` where the task cannot move
    pub(crate) unsafe fn bind_local<T>(
        &self,
        task: T,
        scheduler: S,
        id: super::Id,
        spawned_at: SpawnLocation,
    ) -> (JoinHandle<T::Output>, Option<Notified<S>>)
    where
        S: Schedule,
        T: Future + 'static,
        T::Output: 'static,
    {