diff options
| author | Alix ANNERAUD <[email protected]> | 2025-02-28 16:32:12 +0100 |
|---|---|---|
| committer | Alix ANNERAUD <[email protected]> | 2025-02-28 16:32:12 +0100 |
| commit | 33cf27adf646bacd758b7289ebbf460b24c26fa5 (patch) | |
| tree | e9a82c6e171c42b067e13dee47a80cbed59ec368 /embassy-sync/src/blocking_rwlock | |
| parent | a7ecf14259591ff5b324ec1c7d7c521fabebe7d3 (diff) | |
Refactor blocking read-write lock module structure and improve assertions in ThreadModeRawRwLock
Diffstat (limited to 'embassy-sync/src/blocking_rwlock')
| -rw-r--r-- | embassy-sync/src/blocking_rwlock/mod.rs | 6 | ||||
| -rw-r--r-- | embassy-sync/src/blocking_rwlock/raw.rs | 12 |
2 files changed, 12 insertions, 6 deletions
diff --git a/embassy-sync/src/blocking_rwlock/mod.rs b/embassy-sync/src/blocking_rwlock/mod.rs index a304b77d6..a8fb7d6bc 100644 --- a/embassy-sync/src/blocking_rwlock/mod.rs +++ b/embassy-sync/src/blocking_rwlock/mod.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | //! Blocking read-write lock. | 1 | //! Blocking read-write lock. |
| 2 | //! | 2 | //! |
| 3 | //! This module provides a blocking read-write lock that can be used to synchronize data. | 3 | //! This module provides a blocking read-write lock that can be used to synchronize data. |
| 4 | pub mod raw_rwlock; | 4 | pub mod raw; |
| 5 | 5 | ||
| 6 | use core::cell::UnsafeCell; | 6 | use core::cell::UnsafeCell; |
| 7 | 7 | ||
| 8 | use self::raw_rwlock::RawRwLock; | 8 | use self::raw::RawRwLock; |
| 9 | 9 | ||
| 10 | /// Blocking read-write lock (not async) | 10 | /// Blocking read-write lock (not async) |
| 11 | /// | 11 | /// |
| @@ -218,4 +218,4 @@ mod thread_mode_rwlock { | |||
| 218 | // Drop of the inner `T` happens after this. | 218 | // Drop of the inner `T` happens after this. |
| 219 | } | 219 | } |
| 220 | } | 220 | } |
| 221 | } \ No newline at end of file | 221 | } |
diff --git a/embassy-sync/src/blocking_rwlock/raw.rs b/embassy-sync/src/blocking_rwlock/raw.rs index 85e8374b5..7725edfa5 100644 --- a/embassy-sync/src/blocking_rwlock/raw.rs +++ b/embassy-sync/src/blocking_rwlock/raw.rs | |||
| @@ -126,13 +126,19 @@ mod thread_mode { | |||
| 126 | unsafe impl RawRwLock for ThreadModeRawRwLock { | 126 | unsafe impl RawRwLock for ThreadModeRawRwLock { |
| 127 | const INIT: Self = Self::new(); | 127 | const INIT: Self = Self::new(); |
| 128 | fn read_lock<R>(&self, f: impl FnOnce() -> R) -> R { | 128 | fn read_lock<R>(&self, f: impl FnOnce() -> R) -> R { |
| 129 | assert!(in_thread_mode(), "ThreadModeRwLock can only be locked from thread mode."); | 129 | assert!( |
| 130 | in_thread_mode(), | ||
| 131 | "ThreadModeRwLock can only be locked from thread mode." | ||
| 132 | ); | ||
| 130 | 133 | ||
| 131 | f() | 134 | f() |
| 132 | } | 135 | } |
| 133 | 136 | ||
| 134 | fn write_lock<R>(&self, f: impl FnOnce() -> R) -> R { | 137 | fn write_lock<R>(&self, f: impl FnOnce() -> R) -> R { |
| 135 | assert!(in_thread_mode(), "ThreadModeRwLock can only be locked from thread mode."); | 138 | assert!( |
| 139 | in_thread_mode(), | ||
| 140 | "ThreadModeRwLock can only be locked from thread mode." | ||
| 141 | ); | ||
| 136 | 142 | ||
| 137 | f() | 143 | f() |
| 138 | } | 144 | } |
| @@ -156,4 +162,4 @@ mod thread_mode { | |||
| 156 | } | 162 | } |
| 157 | } | 163 | } |
| 158 | #[cfg(any(cortex_m, feature = "std"))] | 164 | #[cfg(any(cortex_m, feature = "std"))] |
| 159 | pub use thread_mode::*; \ No newline at end of file | 165 | pub use thread_mode::*; |
