From 1121a8eb23f6f0edd9f41cdc08331d40e18105ee Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 3 Apr 2020 15:45:29 -0700 Subject: sync: ensure Mutex, RwLock, and Semaphore futures are Send + Sync (#2375) Previously, the `Mutex::lock`, `RwLock::{read, write}`, and `Semaphore::acquire` futures in `tokio::sync` implemented `Send + Sync` automatically. This was by virtue of being implemented using a `poll_fn` that only closed over `Send + Sync` types. However, this broke in PR #2325, which rewrote those types using the new `batch_semaphore`. Now, they await an `Acquire` future, which contains a `Waiter`, which internally contains an `UnsafeCell`, and thus does not implement `Sync`. Since removing previously implemented traits breaks existing code, this inadvertantly caused a breaking change. There were tests ensuring that the `Mutex`, `RwLock`, and `Semaphore` types themselves were `Send + Sync`, but no tests that the _futures they return_ implemented those traits. I've fixed this by adding an explicit impl of `Sync` for the `batch_semaphore::Acquire` future. Since the `Waiter` type held by this struct is only accessed when borrowed mutably, it is safe for it to implement `Sync`. Additionally, I've added to the bounds checks for the effected `tokio::sync` types to ensure that returned futures continue to implement `Send + Sync` in the future. --- tokio/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tokio/src/lib.rs') diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 7db4cb30..d0cb5fa4 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/tokio/0.2.15")] +#![doc(html_root_url = "https://docs.rs/tokio/0.2.16")] #![allow( clippy::cognitive_complexity, clippy::large_enum_variant, -- cgit v1.2.3