diff options
| -rw-r--r-- | embassy-sync/src/blocking_mutex/mod.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/embassy-sync/src/blocking_mutex/mod.rs b/embassy-sync/src/blocking_mutex/mod.rs index 5b0e4144a..a41bc3569 100644 --- a/embassy-sync/src/blocking_mutex/mod.rs +++ b/embassy-sync/src/blocking_mutex/mod.rs | |||
| @@ -54,8 +54,11 @@ impl<R: RawMutex, T> Mutex<R, T> { | |||
| 54 | /// Creates a critical section and grants temporary mutable access to the protected data. | 54 | /// Creates a critical section and grants temporary mutable access to the protected data. |
| 55 | /// | 55 | /// |
| 56 | /// # Safety | 56 | /// # Safety |
| 57 | /// This method is unsafe because calling this method when the mutex is already locked, | 57 | /// |
| 58 | /// either using this method or `lock`, violates Rust's aliasing rules. | 58 | /// This method is marked unsafe because calling this method re-entrantly, i.e. within |
| 59 | /// another `lock_mut` or `lock` closure, violates Rust's aliasing rules. Calling this | ||
| 60 | /// method at the same time from different tasks is safe. For a safe alternative with | ||
| 61 | /// mutable access that never causes UB, use a `RefCell` in a `Mutex`. | ||
| 59 | pub unsafe fn lock_mut<U>(&self, f: impl FnOnce(&mut T) -> U) -> U { | 62 | pub unsafe fn lock_mut<U>(&self, f: impl FnOnce(&mut T) -> U) -> U { |
| 60 | self.raw.lock(|| { | 63 | self.raw.lock(|| { |
| 61 | let ptr = self.data.get() as *mut T; | 64 | let ptr = self.data.get() as *mut T; |
