1///|
2type Mutex
3
4///|
5extern "c" fn uv_mutex_make() -> type Mutex
Mutex = "moonbit_uv_mutex_make"
6
7///|
8extern "c" fn uv_mutex_init(mutex : type Mutex
Mutex) -> Int
Int = "moonbit_uv_mutex_init"
9
10///|
11pub fn type Mutex
Mutex::() -> Mutex!Errno
new() -> type Mutex
Mutex!type! Errno Status
Errno {
12 let Mutex
mutex = () -> Mutex
uv_mutex_make()
13 let Int
status = (mutex : Mutex) -> Int
uv_mutex_init(Mutex
mutex)
14 if Int
status (x : Int, y : Int) -> Bool
!= 0 {
15 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
16 }
17 return Mutex
mutex
18}
19
20///|
21extern "c" fn uv_mutex_copy(mutex : type Mutex
Mutex, other : type Mutex
Mutex) = "moonbit_uv_mutex_copy"
22
23///|
24extern "c" fn uv_mutex_lock(mutex : type Mutex
Mutex) = "moonbit_uv_mutex_lock"
25
26///|
27extern "c" fn uv_mutex_trylock(mutex : type Mutex
Mutex) -> Int
Int = "moonbit_uv_mutex_trylock"
28
29///|
30extern "c" fn uv_mutex_unlock(mutex : type Mutex
Mutex) = "moonbit_uv_mutex_unlock"
31
32///|
33pub fn type Mutex
Mutex::(self : Mutex) -> Unit
lock(Mutex
self : type Mutex
Mutex) -> Unit
Unit {
34 (mutex : Mutex) -> Unit
uv_mutex_lock(Mutex
self)
35}
36
37///|
38pub fn type Mutex
Mutex::(self : Mutex) -> Unit!Errno
trylock(Mutex
self : type Mutex
Mutex) -> Unit
Unit!type! Errno Status
Errno {
39 let Int
status = (mutex : Mutex) -> Int
uv_mutex_trylock(Mutex
self)
40 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
41 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
42 }
43}
44
45///|
46pub fn type Mutex
Mutex::(self : Mutex) -> Unit
unlock(Mutex
self : type Mutex
Mutex) -> Unit
Unit {
47 (mutex : Mutex) -> Unit
uv_mutex_unlock(Mutex
self)
48}
49
50///|
51pub trait trait Copy {
copy(Self) -> Self
}
Copy {
52 (Self) -> Self
copy(type parameter Self
Self) -> type parameter Self
Self
53}
54
55///|
56pub impl trait Copy {
copy(Self) -> Self
}
Copy for type Mutex
Mutex with (self : Mutex) -> Mutex
copy(Mutex
self : type Mutex
Mutex) -> type Mutex
Mutex {
57 let Mutex
other = () -> Mutex
uv_mutex_make()
58 (mutex : Mutex, other : Mutex) -> Unit
uv_mutex_copy(Mutex
self, Mutex
other)
59 return Mutex
other
60}
61