Skip to content

Commit c9d736a

Browse files
authored
feat: Mark StackSlot as Sync
Since it has no interior mutability it should be safe to share between threads. Signed-off-by: John Nunley <[email protected]>
1 parent 3a49a00 commit c9d736a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
//!
6868
//! [`portable-atomic`]: https://crates.io/crates/portable-atomic
6969
70-
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
70+
#![cfg_attr(not(feature = "std"), no_std)]
7171
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
7272
#![doc(
7373
html_favicon_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
@@ -76,14 +76,18 @@
7676
html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
7777
)]
7878

79+
#[cfg(not(feature = "std"))]
7980
extern crate alloc;
81+
#[cfg(feature = "std")]
82+
extern crate std as alloc;
8083

8184
#[cfg_attr(feature = "std", path = "std.rs")]
8285
#[cfg_attr(not(feature = "std"), path = "no_std.rs")]
8386
mod sys;
8487

8588
mod notify;
8689

90+
#[cfg(not(feature = "std"))]
8791
use alloc::boxed::Box;
8892

8993
use core::borrow::Borrow;
@@ -1365,6 +1369,9 @@ fn __test_send_and_sync() {
13651369
fn _assert_sync<T: Sync>() {}
13661370

13671371
_assert_send::<crate::__private::StackSlot<'_, ()>>();
1372+
_assert_sync::<crate::__private::StackSlot<'_, ()>>();
1373+
_assert_send::<crate::__private::StackListener<'_, '_, ()>>();
1374+
_assert_sync::<crate::__private::StackListener<'_, '_, ()>>();
13681375
_assert_send::<Event<()>>();
13691376
_assert_sync::<Event<()>>();
13701377
_assert_send::<EventListener<()>>();
@@ -1410,6 +1417,7 @@ pub mod __private {
14101417
impl<T> core::panic::UnwindSafe for StackSlot<'_, T> {}
14111418
impl<T> core::panic::RefUnwindSafe for StackSlot<'_, T> {}
14121419
unsafe impl<T> Send for StackSlot<'_, T> {}
1420+
unsafe impl<T> Sync for StackSlot<'_, T> {}
14131421

14141422
impl<'ev, T> StackSlot<'ev, T> {
14151423
/// Create a new `StackSlot` on the stack.

src/no_std.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ unsafe impl<T: Send> Sync for Mutex<T> {}
832832
#[cfg(test)]
833833
mod tests {
834834
use super::*;
835-
use crate::Task;
836835

837836
#[cfg(target_family = "wasm")]
838837
use wasm_bindgen_test::wasm_bindgen_test as test;

0 commit comments

Comments
 (0)