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

rt: EnterGuard should not be Send #5766

Merged
merged 1 commit into from
Jun 5, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tokio/src/runtime/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ cfg_rt! {
pub(crate) struct SetCurrentGuard {
old_handle: Option<scheduler::Handle>,
old_seed: RngSeed,
// Should not be `Send` since it must be *dropped* on the same thread as
// created, but there is no issue with sync access.
_p: PhantomData<crate::util::markers::SyncNotSend>,
}

/// Guard tracking that a caller has entered a runtime context.
Expand Down Expand Up @@ -308,6 +311,7 @@ cfg_rt! {
SetCurrentGuard {
old_handle,
old_seed,
_p: PhantomData,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/util/markers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Marker for types that are `Sync` but not `Send`
pub(crate) struct SyncNotSend(*mut ());

unsafe impl Sync for SyncNotSend {}
2 changes: 2 additions & 0 deletions tokio/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ pub(crate) mod error;

#[cfg(feature = "io-util")]
pub(crate) mod memchr;

pub(crate) mod markers;
2 changes: 1 addition & 1 deletion tokio/tests/async_send_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ async_assert_fn!(tokio::task::unconstrained(BoxFutureSend<()>): Send & !Sync & U
async_assert_fn!(tokio::task::unconstrained(BoxFutureSync<()>): Send & Sync & Unpin);

assert_value!(tokio::runtime::Builder: Send & Sync & Unpin);
assert_value!(tokio::runtime::EnterGuard<'_>: Send & Sync & Unpin);
assert_value!(tokio::runtime::EnterGuard<'_>: !Send & Sync & Unpin);
assert_value!(tokio::runtime::Handle: Send & Sync & Unpin);
assert_value!(tokio::runtime::Runtime: Send & Sync & Unpin);

Expand Down