Skip to content

Commit

Permalink
Soundness fix: ensure the CriticalSection token is not Send/Sync so i…
Browse files Browse the repository at this point in the history
…t can only be used in the thread that acquired it.
  • Loading branch information
Dirbaio committed Oct 16, 2024
1 parent 91e8b9e commit 1a7c868
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub use self::mutex::Mutex;
#[derive(Clone, Copy, Debug)]
pub struct CriticalSection<'cs> {
_private: PhantomData<&'cs ()>,

// Prevent CriticalSection from being Send or Sync
// https://github.com/rust-embedded/critical-section/issues/55
_not_send_sync: PhantomData<*mut ()>,
}

impl<'cs> CriticalSection<'cs> {
Expand All @@ -40,6 +44,7 @@ impl<'cs> CriticalSection<'cs> {
pub unsafe fn new() -> Self {
CriticalSection {
_private: PhantomData,
_not_send_sync: PhantomData,
}
}
}
Expand Down

0 comments on commit 1a7c868

Please sign in to comment.