diff --git a/src/hotplug.rs b/src/hotplug.rs index 7bdc681..8a8d314 100644 --- a/src/hotplug.rs +++ b/src/hotplug.rs @@ -33,3 +33,9 @@ pub enum HotplugEvent { /// A device has been disconnected. Disconnected(DeviceId), } + +#[test] +fn assert_send_sync() { + fn require_send_sync() {} + require_send_sync::(); +} diff --git a/src/platform/macos_iokit/hotplug.rs b/src/platform/macos_iokit/hotplug.rs index 1b1c88a..175b9be 100644 --- a/src/platform/macos_iokit/hotplug.rs +++ b/src/platform/macos_iokit/hotplug.rs @@ -141,6 +141,10 @@ impl MacHotplugWatch { } } +// Safety: Structurally Send and only method is &mut self, so Sync +// doesn't have any additional requirements. +unsafe impl Sync for MacHotplugWatch {} + fn register_notification( port: &NotificationPort, dictionary: &CFDictionary, diff --git a/src/platform/windows_winusb/hotplug.rs b/src/platform/windows_winusb/hotplug.rs index 67cf96b..a151c13 100644 --- a/src/platform/windows_winusb/hotplug.rs +++ b/src/platform/windows_winusb/hotplug.rs @@ -115,6 +115,12 @@ impl WindowsHotplugWatch { } } +// Safety: Effectively a Box, which is Send+Sync; +// `registration` is accessed only in `Drop` and `CM_Unregister_Notification` +// docs mention using a threadpool to call the function. +unsafe impl Send for WindowsHotplugWatch {} +unsafe impl Sync for WindowsHotplugWatch {} + impl Drop for WindowsHotplugWatch { fn drop(&mut self) { unsafe {