We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 41b8001 commit b9ed877Copy full SHA for b9ed877
src/lock/mod.rs
@@ -7,3 +7,24 @@ pub trait LockObject: Sized {}
7
pub trait Mtx<K: Kernel>: Sized {
8
fn lock_mut(&mut self) -> &mut K::LockObject;
9
}
10
+
11
+/// RAII struct to unlock a mutex when dropped.
12
+pub struct MtxLock<K: Kernel> {
13
+ kern: K,
14
+ mtx: *mut K::Mtx,
15
+}
16
17
+impl<K: Kernel> MtxLock<K> {
18
+ /// # Safety
19
+ /// `mtx` cannot be null.
20
+ pub unsafe fn new(kern: K, mtx: *mut K::Mtx) -> Self {
21
+ kern.mtx_lock_flags(mtx, 0, c"".as_ptr(), 0);
22
+ Self { kern, mtx }
23
+ }
24
25
26
+impl<K: Kernel> Drop for MtxLock<K> {
27
+ fn drop(&mut self) {
28
+ unsafe { self.kern.mtx_unlock_flags(self.mtx, 0, c"".as_ptr(), 0) };
29
30
0 commit comments