diff --git a/rpi-led-matrix/CHANGELOG.md b/rpi-led-matrix/CHANGELOG.md index 8a3b9d3..e28746b 100644 --- a/rpi-led-matrix/CHANGELOG.md +++ b/rpi-led-matrix/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Link to pure rust rewrite of `rpi-led-matrix` - dependabot updates of CI only crates - Update `embedded-graphics-core` to `0.4` and `embedded-graphics` to `0.8` +- Implement Send + Sync for LedCanvas ## [0.4.0] - 2022-01-05 diff --git a/rpi-led-matrix/src/canvas.rs b/rpi-led-matrix/src/canvas.rs index 2376ed3..a0d0203 100644 --- a/rpi-led-matrix/src/canvas.rs +++ b/rpi-led-matrix/src/canvas.rs @@ -16,6 +16,16 @@ pub struct LedCanvas { pub(crate) handle: *mut ffi::CLedCanvas, } +/// Implements both the [`Send`] and [`Sync`] traits for [`LedCanvas`]. +/// +/// The underlying handle referenced by this FFI is [heap-allocated], +/// allowing safe ownership transfer between threads. Additionally, +/// references to this handle can be safely shared across thread boundaries. +/// +/// [heap-allocated]: https://github.com/hzeller/rpi-rgb-led-matrix/blob/0ff6a6973f95d14e3206bcef1201237097fa8edd/lib/led-matrix.cc#L501 +unsafe impl Send for LedCanvas {} +unsafe impl Sync for LedCanvas {} + impl LedCanvas { /// Retrieves the width & height of the canvas #[must_use]