Skip to content

Commit

Permalink
Merge 'tokio-1.21.1' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Sep 13, 2022
2 parents 3a4f18b + dea1cd4 commit 0d68bef
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:

```toml
[dependencies]
tokio = { version = "1.21.0", features = ["full"] }
tokio = { version = "1.21.1", features = ["full"] }
```
Then, on your main.rs:

Expand Down
10 changes: 10 additions & 0 deletions tokio/CHANGELOG.md
@@ -1,3 +1,13 @@
# 1.21.1 (September 13, 2022)

### Fixed

- net: fix dependency resolution for socket2 ([#5000])
- task: ignore failure to set TLS in `LocalSet` Drop ([#4976])

[#4976]: https://github.com/tokio-rs/tokio/pull/4976
[#5000]: https://github.com/tokio-rs/tokio/pull/5000

# 1.21.0 (September 2, 2022)

This release is the first release of Tokio to intentionally support WASM. The
Expand Down
7 changes: 4 additions & 3 deletions tokio/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ name = "tokio"
# - README.md
# - Update CHANGELOG.md.
# - Create "v1.0.x" git tag.
version = "1.21.0"
version = "1.21.1"
edition = "2018"
rust-version = "1.49"
authors = ["Tokio Contributors <team@tokio.rs>"]
Expand Down Expand Up @@ -51,14 +51,15 @@ net = [
"mio/os-poll",
"mio/os-ext",
"mio/net",
"socket2",
"winapi/fileapi",
"winapi/handleapi",
"winapi/namedpipeapi",
"winapi/winbase",
"winapi/winnt",
"winapi/minwindef",
"winapi/accctrl",
"winapi/aclapi"
"winapi/aclapi",
]
process = [
"bytes",
Expand Down Expand Up @@ -118,7 +119,7 @@ num_cpus = { version = "1.8.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }

[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies]
socket2 = { version = "0.4.4", features = [ "all" ] }
socket2 = { version = "0.4.4", optional = true, features = [ "all" ] }

# Currently unstable. The API exposed by these features may be broken at any time.
# Requires `--cfg tokio_unstable` to enable.
Expand Down
2 changes: 1 addition & 1 deletion tokio/README.md
Expand Up @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:

```toml
[dependencies]
tokio = { version = "1.21.0", features = ["full"] }
tokio = { version = "1.21.1", features = ["full"] }
```
Then, on your main.rs:

Expand Down
33 changes: 32 additions & 1 deletion tokio/src/task/local.rs
Expand Up @@ -635,6 +635,37 @@ impl LocalSet {
f()
})
}

/// This method is like `with`, but it just calls `f` without setting the thread-local if that
/// fails.
fn with_if_possible<T>(&self, f: impl FnOnce() -> T) -> T {
let mut f = Some(f);

let res = CURRENT.try_with(|ctx| {
struct Reset<'a> {
ctx_ref: &'a RcCell<Context>,
val: Option<Rc<Context>>,
}
impl<'a> Drop for Reset<'a> {
fn drop(&mut self) {
self.ctx_ref.replace(self.val.take());
}
}
let old = ctx.replace(Some(self.context.clone()));

let _reset = Reset {
ctx_ref: ctx,
val: old,
};

(f.take().unwrap())()
});

match res {
Ok(res) => res,
Err(_access_error) => (f.take().unwrap())(),
}
}
}

cfg_unstable! {
Expand Down Expand Up @@ -746,7 +777,7 @@ impl Default for LocalSet {

impl Drop for LocalSet {
fn drop(&mut self) {
self.with(|| {
self.with_if_possible(|| {
// Shut down all tasks in the LocalOwnedTasks and close it to
// prevent new tasks from ever being added.
self.context.owned.close_and_shutdown_all();
Expand Down
21 changes: 21 additions & 0 deletions tokio/tests/task_local_set.rs
Expand Up @@ -311,6 +311,27 @@ fn join_local_future_elsewhere() {
});
}

// Tests for <https://github.com/tokio-rs/tokio/issues/4973>
#[cfg(not(tokio_wasi))] // Wasi doesn't support threads
#[tokio::test(flavor = "multi_thread")]
async fn localset_in_thread_local() {
thread_local! {
static LOCAL_SET: LocalSet = LocalSet::new();
}

// holds runtime thread until end of main fn.
let (_tx, rx) = oneshot::channel::<()>();
let handle = tokio::runtime::Handle::current();

std::thread::spawn(move || {
LOCAL_SET.with(|local_set| {
handle.block_on(local_set.run_until(async move {
let _ = rx.await;
}))
});
});
}

#[test]
fn drop_cancels_tasks() {
use std::rc::Rc;
Expand Down

0 comments on commit 0d68bef

Please sign in to comment.