diff --git a/rtic-macros/CHANGELOG.md b/rtic-macros/CHANGELOG.md index f9a9445e5d07..2a2f44274894 100644 --- a/rtic-macros/CHANGELOG.md +++ b/rtic-macros/CHANGELOG.md @@ -7,6 +7,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top! ## [Unreleased] +### Fixed + +- Generated mutexes for shared resourses no longer implement `Send`. They are meant to be used inside a task locally. + ### Added - Outer attributes applied to RTIC app module are now forwarded to the generated code. diff --git a/rtic-macros/src/codegen/shared_resources.rs b/rtic-macros/src/codegen/shared_resources.rs index 5e8ca9ae77ca..92657c8fe697 100644 --- a/rtic-macros/src/codegen/shared_resources.rs +++ b/rtic-macros/src/codegen/shared_resources.rs @@ -62,9 +62,14 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { #[allow(non_camel_case_types)] #(#cfgs)* pub struct #shared_name<'a> { - __rtic_internal_p: ::core::marker::PhantomData<&'a ()>, + __rtic_internal_p: ::core::marker::PhantomData<(&'a (), *const u8)>, } + // Opt out from `Send`. + // `#shared_name` is trivially `Sync` because there are no `&self` methods. + // See https://doc.rust-lang.org/std/sync/struct.Exclusive.html . + unsafe impl<'a> Sync for #shared_name<'a> {} + #(#cfgs)* impl<'a> #shared_name<'a> { #[inline(always)]