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

implement Sync for SharedStream #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/channel/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,16 @@ mod if_alloc {
}
}

// The stream is thread-safe as long as a thread-safe mutex is used
// and the inner future cannot be accessed by a shared reference.
unsafe impl<MutexType: RawMutex + Sync, T: Send, A> Sync
for SharedStream<MutexType, T, A>
where
A: RingBuf<Item = T>,
{
}


// Export parking_lot based shared channels in std mode
#[cfg(feature = "std")]
mod if_std {
Expand Down
7 changes: 7 additions & 0 deletions tests/mpmc_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,13 @@ mod if_std {
is_send(&send_fut);
}

#[test]
fn shared_channel_stream_is_sync() {
let (_, receiver) = channel::<i32>(1);
let stream = receiver.into_stream();
is_sync(&stream);
}

// Check if SharedChannel can be used in traits
pub trait StreamTrait {
type Output;
Expand Down