Skip to content

Commit fcfe055

Browse files
Implement Send + Sync for LedCanvas (#47)
Since led_matrix_swap_on_vsync() will block until the next vsync, implementing the Send + Sync traits for LedCanvas will allow the canvas to be sent between a render thread and a draw thread. Since the underlying canvas is created with CreateFrameCanvas(), which allocates the canvas memory on the heap, it is safe to share between threads.
1 parent 1baa92f commit fcfe055

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

rpi-led-matrix/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Link to pure rust rewrite of `rpi-led-matrix`
1212
- dependabot updates of CI only crates
1313
- Update `embedded-graphics-core` to `0.4` and `embedded-graphics` to `0.8`
14+
- Implement Send + Sync for LedCanvas
1415

1516
## [0.4.0] - 2022-01-05
1617

rpi-led-matrix/src/canvas.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ pub struct LedCanvas {
1616
pub(crate) handle: *mut ffi::CLedCanvas,
1717
}
1818

19+
/// Implements both the [`Send`] and [`Sync`] traits for [`LedCanvas`].
20+
///
21+
/// The underlying handle referenced by this FFI is [heap-allocated],
22+
/// allowing safe ownership transfer between threads. Additionally,
23+
/// references to this handle can be safely shared across thread boundaries.
24+
///
25+
/// [heap-allocated]: https://github.com/hzeller/rpi-rgb-led-matrix/blob/0ff6a6973f95d14e3206bcef1201237097fa8edd/lib/led-matrix.cc#L501
26+
unsafe impl Send for LedCanvas {}
27+
unsafe impl Sync for LedCanvas {}
28+
1929
impl LedCanvas {
2030
/// Retrieves the width & height of the canvas
2131
#[must_use]

0 commit comments

Comments
 (0)