Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OwnedTasks in LocalSet #3950

Merged
merged 2 commits into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tokio/src/runtime/task/mod.rs
Expand Up @@ -14,7 +14,7 @@ mod join;
pub use self::join::JoinHandle;

mod list;
pub(super) use self::list::OwnedTasks;
pub(crate) use self::list::OwnedTasks;

mod raw;
use self::raw::RawTask;
Expand Down
12 changes: 4 additions & 8 deletions tokio/src/task/local.rs
@@ -1,7 +1,6 @@
//! Runs `!Send` futures on the current thread.
use crate::runtime::task::{self, JoinHandle, Task};
use crate::runtime::task::{self, JoinHandle, OwnedTasks, Task};
use crate::sync::AtomicWaker;
use crate::util::linked_list::{Link, LinkedList};

use std::cell::{Cell, RefCell};
use std::collections::VecDeque;
Expand Down Expand Up @@ -233,7 +232,7 @@ struct Context {

struct Tasks {
/// Collection of all active tasks spawned onto this executor.
owned: LinkedList<Task<Arc<Shared>>, <Task<Arc<Shared>> as Link>::Target>,
owned: OwnedTasks<Arc<Shared>>,

/// Local run queue sender and receiver.
queue: VecDeque<task::Notified<Arc<Shared>>>,
Expand Down Expand Up @@ -334,7 +333,7 @@ impl LocalSet {
tick: Cell::new(0),
context: Context {
tasks: RefCell::new(Tasks {
owned: LinkedList::new(),
owned: OwnedTasks::new(),
queue: VecDeque::with_capacity(INITIAL_CAPACITY),
}),
shared: Arc::new(Shared {
Expand Down Expand Up @@ -682,17 +681,14 @@ impl task::Schedule for Arc<Shared> {
}

fn release(&self, task: &Task<Self>) -> Option<Task<Self>> {
use std::ptr::NonNull;

CURRENT.with(|maybe_cx| {
let cx = maybe_cx.expect("scheduler context missing");

assert!(cx.shared.ptr_eq(self));

let ptr = NonNull::from(task.header());
// safety: task must be contained by list. It is inserted into the
// list in `bind`.
unsafe { cx.tasks.borrow_mut().owned.remove(ptr) }
unsafe { cx.tasks.borrow_mut().owned.remove(&task) }
})
}

Expand Down