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 Send for Stream on certain platforms #840

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
23 changes: 23 additions & 0 deletions src/platform/maybe_send.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! The following zero-sized type is for applying [`Send`]/[`Sync`]` restrictions to ensure
//! consistent behaviour across different platforms. The verbosely named type is used
//! (rather than using the markers directly) in the hope of making the compile errors
//! slightly more helpful.

// TODO: Remove this in favour of using negative trait bounds if they stabilise.

/// A marker used to remove the `Send` and `Sync` traits.
pub(crate) struct NotSendSyncAcrossAllPlatforms(std::marker::PhantomData<*mut ()>);

impl Default for NotSendSyncAcrossAllPlatforms {
fn default() -> Self {
NotSendSyncAcrossAllPlatforms(std::marker::PhantomData)
}
}

// TODO: Implement Send on platforms which support it.

#[cfg(any(
// Windows with WASAPI allows for a Send Stream
all(windows, not(feature = "asio")),
))]
unsafe impl Send for NotSendSyncAcrossAllPlatforms {}
20 changes: 4 additions & 16 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//! type and its associated [`Device`], [`Stream`] and other associated types. These
//! types are useful in the case that users require switching between audio host APIs at runtime.

mod maybe_send;

pub(crate) use maybe_send::*;

#[doc(inline)]
pub use self::platform_impl::*;

Expand Down Expand Up @@ -724,19 +728,3 @@ mod platform_impl {
.into()
}
}

// The following zero-sized types are for applying Send/Sync restrictions to ensure
// consistent behaviour across different platforms. These verbosely named types are used
// (rather than using the markers directly) in the hope of making the compile errors
// slightly more helpful.
//
// TODO: Remove these in favour of using negative trait bounds if they stabilise.

// A marker used to remove the `Send` and `Sync` traits.
struct NotSendSyncAcrossAllPlatforms(std::marker::PhantomData<*mut ()>);

impl Default for NotSendSyncAcrossAllPlatforms {
fn default() -> Self {
NotSendSyncAcrossAllPlatforms(std::marker::PhantomData)
}
}
Loading