Skip to content

Commit 94fbbb8

Browse files
committed
zephyr: Remove 'unsafe' from sys::Mutex::unlock
Although this function has constraints on how it can be used (the thread that calls unlock must also have called lock). However, according to the documentation, it detects this, and returns an error. As such, the wrapper in Rust does not need to be `unsafe` but can merely reflect that error code in the `Result` that it returns. Signed-off-by: David Brown <[email protected]>
1 parent b9570ca commit 94fbbb8

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

samples/philosophers/src/sysmutex.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ impl ForkSync for SysMutexSync {
4040
}
4141

4242
fn release(&self, index: usize) {
43-
unsafe {
44-
self.locks[index].unlock().unwrap();
45-
}
43+
self.locks[index].unlock().unwrap();
4644
}
4745
}
4846

zephyr/src/sys/sync/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Mutex {
7575
///
7676
/// The mutex must already be locked by the calling thread. Mutexes may not be unlocked in
7777
/// ISRs.
78-
pub unsafe fn unlock(&self) -> Result<()> {
78+
pub fn unlock(&self) -> Result<()> {
7979
to_result_void(unsafe { k_mutex_unlock(self.item) })
8080
}
8181
}

0 commit comments

Comments
 (0)