Skip to content

Commit

Permalink
Add send feature flag
Browse files Browse the repository at this point in the history
Since most udev libraries should be safe to access across threads, this flag
allows a consumer to opt in to allowing cross-thread access. However, since
this isn't necessarily guaranteed, it's not enabled by default.
  • Loading branch information
endrift authored and Drakulix committed Jan 21, 2025
1 parent 8aa259d commit 7511349
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ pkg-config = "0.3.3" #force a newer version for libudev-sys to fix minimal versi
[features]
mio = ["mio10"] # mio feature defaults to the newest mio version
hwdb = []
send = []
3 changes: 3 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ impl Drop for Device {
}
}

#[cfg(feature = "send")]
unsafe impl Send for Device {}

as_ffi_with_context!(Device, device, ffi::udev_device, ffi::udev_device_ref);

/// A convenience alias for a list of properties, bound to a device.
Expand Down
3 changes: 3 additions & 0 deletions src/enumerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ impl Drop for Enumerator {
}
}

#[cfg(feature = "send")]
unsafe impl Send for Enumerator {}

as_ffi_with_context!(
Enumerator,
enumerator,
Expand Down
3 changes: 3 additions & 0 deletions src/hwdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ impl Drop for Hwdb {
}
}

#[cfg(feature = "send")]
unsafe impl Send for Hwdb {}

as_ffi!(Hwdb, hwdb, ffi::udev_hwdb, ffi::udev_hwdb_ref);

impl Hwdb {
Expand Down
4 changes: 4 additions & 0 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub struct List<'a, T: 'a, E: 'a> {
pub(crate) entry: *mut ffi::udev_list_entry,
pub(crate) phantom: PhantomData<&'a (T, E)>,
}

#[cfg(feature = "send")]
unsafe impl<T, E> Send for List<'_, T, E> {}

pub type EntryList<'a, T> = List<'a, T, Entry<'a>>;

impl<'a, T> Iterator for EntryList<'a, T> {
Expand Down
3 changes: 3 additions & 0 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl Drop for Builder {
}
}

#[cfg(feature = "send")]
unsafe impl Send for Builder {}

as_ffi_with_context!(Builder, monitor, ffi::udev_monitor, ffi::udev_monitor_ref);

/// The event source to monitor.
Expand Down
3 changes: 3 additions & 0 deletions src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ impl Drop for Udev {
}
}

#[cfg(feature = "send")]
unsafe impl Send for Udev {}

as_ffi!(Udev, udev, ffi::udev, ffi::udev_ref);

impl Udev {
Expand Down

0 comments on commit 7511349

Please sign in to comment.