blob: b5c75f738d228e170f0d07d21a7a7e0e24d353c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
use crate::ffi::c_void;
use crate::ptr;
use crate::sys::hermit::abi;
pub struct Mutex {
inner: *const c_void,
}
unsafe impl Send for Mutex {}
unsafe impl Sync for Mutex {}
impl Mutex {
pub const fn new() -> Mutex {
Mutex { inner: ptr::null() }
}
#[inline]
pub unsafe fn init(&mut self) {
let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1);
}
#[inline]
pub unsafe fn lock(&self) {
let _ = abi::sem_timedwait(self.inner, 0);
}
#[inline]
pub unsafe fn unlock(&self) {
let _ = abi::sem_post(self.inner);
}
#[inline]
pub unsafe fn try_lock(&self) -> bool {
let result = abi::sem_trywait(self.inner);
result == 0
}
#[inline]
pub unsafe fn destroy(&self) {
let _ = abi::sem_destroy(self.inner);
}
}
pub struct ReentrantMutex {
inner: *const c_void,
}
impl ReentrantMutex {
pub unsafe fn uninitialized() -> ReentrantMutex {
ReentrantMutex { inner: ptr::null() }
}
#[inline]
pub unsafe fn init(&mut self) {
let _ = abi::recmutex_init(&mut self.inner as *mut *const c_void);
}
#[inline]
pub unsafe fn lock(&self) {
let _ = abi::recmutex_lock(self.inner);
}
#[inline]
pub unsafe fn try_lock(&self) -> bool {
true
}
#[inline]
pub unsafe fn unlock(&self) {
let _ = abi::recmutex_unlock(self.inner);
}
#[inline]
pub unsafe fn destroy(&self) {
let _ = abi::recmutex_destroy(self.inner);
}
}
|