Skip to content

Commit d8e2800

Browse files
committed
zephyr: Use Result for several Zephyr functions
Change the return type for several Zephyr functions to return a Result so that errors can be properly propagated. Signed-off-by: David Brown <[email protected]>
1 parent da653a9 commit d8e2800

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

zephyr/src/sys/sync.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
3333
use core::fmt;
3434

35+
use crate::error::{Result, to_result_void};
3536
use crate::raw::{
3637
k_mutex,
3738
k_mutex_init,
@@ -67,16 +68,15 @@ impl KobjInit<k_mutex, Mutex> for StaticKernelObject<k_mutex> {
6768
}
6869

6970
impl Mutex {
70-
pub fn lock<T>(&self, timeout: T)
71+
pub fn lock<T>(&self, timeout: T) -> Result<()>
7172
where T: Into<Timeout>,
7273
{
7374
let timeout: Timeout = timeout.into();
74-
// TODO: Erro
75-
unsafe { k_mutex_lock(self.item, timeout.0); }
75+
to_result_void(unsafe { k_mutex_lock(self.item, timeout.0) })
7676
}
7777

78-
pub fn unlock(&self) {
79-
unsafe { k_mutex_unlock(self.item); }
78+
pub fn unlock(&self) -> Result<()> {
79+
to_result_void(unsafe { k_mutex_unlock(self.item) })
8080
}
8181
}
8282

@@ -116,6 +116,7 @@ impl StaticMutex {
116116
pub fn init(&self) {
117117
self.init_help(|raw| {
118118
unsafe {
119+
// Init is defined to always return zero, no error possible.
119120
k_mutex_init(raw);
120121
}
121122
})

0 commit comments

Comments
 (0)