Skip to content

Commit

Permalink
Implement Send + Sync for LedCanvas
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
StefanBossbaly committed Dec 22, 2024
1 parent 663c32f commit f8e156a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions rpi-led-matrix/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions rpi-led-matrix/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f8e156a

Please sign in to comment.