From fbfb574a564246722d2a58dbeedf1b23b0129a8a Mon Sep 17 00:00:00 2001 From: Natasha England-Elbro Date: Fri, 12 Apr 2024 12:07:22 +0100 Subject: [PATCH] feat: make Wave Send + Sync --- ctru-rs/Cargo.toml | 1 + ctru-rs/src/services/ndsp/wave.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/ctru-rs/Cargo.toml b/ctru-rs/Cargo.toml index 9583c21..ce0bf08 100644 --- a/ctru-rs/Cargo.toml +++ b/ctru-rs/Cargo.toml @@ -26,6 +26,7 @@ libc = "0.2.121" bitflags = "2.3.3" macaddr = "1.0.1" widestring = "1.0.2" +static_assertions = "1.1.0" [build-dependencies] toml = "0.5" diff --git a/ctru-rs/src/services/ndsp/wave.rs b/ctru-rs/src/services/ndsp/wave.rs index 5389ebd..856020c 100644 --- a/ctru-rs/src/services/ndsp/wave.rs +++ b/ctru-rs/src/services/ndsp/wave.rs @@ -2,6 +2,8 @@ //! //! This modules has all methods and structs required to work with audio waves meant to be played via the [`ndsp`](crate::services::ndsp) service. +use static_assertions::assert_impl_all; + use super::{AudioFormat, Error}; use crate::linear::LinearAllocator; @@ -222,3 +224,13 @@ impl Drop for Wave { } } } + +// Safety: The 2 members we have to watch for are `adpcm_data` and `next` +// we access neither of them directly in the wave API (at least currently) but +// `next` at least _is_ used by the ndsp service internally. Given we do not +// touch `next` ourselves and never should this is not an issue, and as long as +// `adpcm_data` is not touched it should also be fine +unsafe impl Send for Wave {} +unsafe impl Sync for Wave {} + +assert_impl_all!(Wave: Send, Sync);