Skip to content

Commit

Permalink
Merge pull request #47 from tokio-rs/master
Browse files Browse the repository at this point in the history
Sync Fork from Upstream Repo
  • Loading branch information
sthagen committed Jul 13, 2021
2 parents 23f0ba6 + 7a11cfd commit e7ed1a5
Show file tree
Hide file tree
Showing 4 changed files with 570 additions and 285 deletions.
2 changes: 1 addition & 1 deletion tokio/src/runtime/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions tokio/src/task/task_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use pin_project_lite::pin_project;
use std::cell::RefCell;
use std::error::Error;
use std::future::Future;
use std::marker::PhantomPinned;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{fmt, thread};
Expand Down Expand Up @@ -123,6 +124,7 @@ impl<T: 'static> LocalKey<T> {
local: &self,
slot: Some(value),
future: f,
_pinned: PhantomPinned,
}
}

Expand All @@ -147,12 +149,14 @@ impl<T: 'static> LocalKey<T> {
where
F: FnOnce() -> R,
{
let mut scope = TaskLocalFuture {
let scope = TaskLocalFuture {
local: &self,
slot: Some(value),
future: (),
_pinned: PhantomPinned,
};
Pin::new(&mut scope).with_task(|_| f())
crate::pin!(scope);
scope.with_task(|_| f())
}

/// Accesses the current task-local and runs the provided closure.
Expand Down Expand Up @@ -234,6 +238,8 @@ pin_project! {
slot: Option<T>,
#[pin]
future: F,
#[pin]
_pinned: PhantomPinned,
}
}

Expand Down

1 comment on commit e7ed1a5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'sync_mpsc'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: e7ed1a5 Previous: 23f0ba6 Ratio
send_large 61608 ns/iter (± 4442) 24675 ns/iter (± 101) 2.50

This comment was automatically generated by workflow using github-action-benchmark.

CC: @tokio-rs/maintainers

Please sign in to comment.