Relax `Sync` restriction on `Device` and `Host`
Originally this restriction was placed due to uncertainty around the thread safety of the ASIO API. While the ASIO API itself makes no thread-safety guarantees that we are aware of, the `asio-sys` high-level bindings enforce synchronised access to the API and state transitions via a mutex.
This commit is contained in:
parent
ca2aceb536
commit
32d39bcfd3
|
@ -48,18 +48,11 @@ macro_rules! impl_platform_host {
|
||||||
///
|
///
|
||||||
/// This type may be constructed via the **host_from_id** function. **HostId**s may
|
/// This type may be constructed via the **host_from_id** function. **HostId**s may
|
||||||
/// be acquired via the **ALL_HOSTS** const and the **available_hosts** function.
|
/// be acquired via the **ALL_HOSTS** const and the **available_hosts** function.
|
||||||
// `Host` and `Device` cannot assume to be `Sync` as we have not yet been able to confirm
|
pub struct Host(HostInner);
|
||||||
// whether or not the ASIO API is thread-safe.
|
|
||||||
//
|
|
||||||
// TODO: Try to contact ASIO to get more information. Review the existing implementation of
|
|
||||||
// the `asio` backend's `Host` and `Driver` types and see if the existing `Arc`s and
|
|
||||||
// `Mutex`s don't already make the API `Sync`.
|
|
||||||
pub struct Host(HostInner, crate::platform::NotSyncAcrossAllPlatforms);
|
|
||||||
|
|
||||||
/// The **Device** implementation associated with the platform's dynamically dispatched
|
/// The **Device** implementation associated with the platform's dynamically dispatched
|
||||||
/// **Host** type.
|
/// **Host** type.
|
||||||
// See comment above `Host` for reasoning behind `NotSyncAcrossAllPlatforms`.
|
pub struct Device(DeviceInner);
|
||||||
pub struct Device(DeviceInner, crate::platform::NotSyncAcrossAllPlatforms);
|
|
||||||
|
|
||||||
/// The **Devices** iterator associated with the platform's dynamically dispatched **Host**
|
/// The **Devices** iterator associated with the platform's dynamically dispatched **Host**
|
||||||
/// type.
|
/// type.
|
||||||
|
@ -348,7 +341,7 @@ macro_rules! impl_platform_host {
|
||||||
|
|
||||||
impl From<DeviceInner> for Device {
|
impl From<DeviceInner> for Device {
|
||||||
fn from(d: DeviceInner) -> Self {
|
fn from(d: DeviceInner) -> Self {
|
||||||
Device(d, Default::default())
|
Device(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,7 +353,7 @@ macro_rules! impl_platform_host {
|
||||||
|
|
||||||
impl From<HostInner> for Host {
|
impl From<HostInner> for Host {
|
||||||
fn from(h: HostInner) -> Self {
|
fn from(h: HostInner) -> Self {
|
||||||
Host(h, Default::default())
|
Host(h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,15 +547,6 @@ mod platform_impl {
|
||||||
// A marker used to remove the `Send` and `Sync` traits.
|
// A marker used to remove the `Send` and `Sync` traits.
|
||||||
struct NotSendSyncAcrossAllPlatforms(std::marker::PhantomData<*mut ()>);
|
struct NotSendSyncAcrossAllPlatforms(std::marker::PhantomData<*mut ()>);
|
||||||
|
|
||||||
// A marker used to remove the `Sync` traits.
|
|
||||||
struct NotSyncAcrossAllPlatforms(std::marker::PhantomData<std::cell::RefCell<()>>);
|
|
||||||
|
|
||||||
impl Default for NotSyncAcrossAllPlatforms {
|
|
||||||
fn default() -> Self {
|
|
||||||
NotSyncAcrossAllPlatforms(std::marker::PhantomData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for NotSendSyncAcrossAllPlatforms {
|
impl Default for NotSendSyncAcrossAllPlatforms {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
NotSendSyncAcrossAllPlatforms(std::marker::PhantomData)
|
NotSendSyncAcrossAllPlatforms(std::marker::PhantomData)
|
||||||
|
|
Loading…
Reference in New Issue