]> git.proxmox.com Git - rustc.git/blame - library/std/src/sys/unsupported/locks/mutex.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / library / std / src / sys / unsupported / locks / mutex.rs
CommitLineData
29967ef6 1use crate::cell::Cell;
abe05a73
XL
2
3pub struct Mutex {
29967ef6
XL
4 // This platform has no threads, so we can use a Cell here.
5 locked: Cell<bool>,
abe05a73
XL
6}
7
29967ef6
XL
8pub type MovableMutex = Mutex;
9
abe05a73 10unsafe impl Send for Mutex {}
3dfed10e 11unsafe impl Sync for Mutex {} // no threads on this platform
abe05a73
XL
12
13impl Mutex {
14 pub const fn new() -> Mutex {
29967ef6 15 Mutex { locked: Cell::new(false) }
abe05a73
XL
16 }
17
18 #[inline]
dfeec247 19 pub unsafe fn init(&mut self) {}
abe05a73
XL
20
21 #[inline]
22 pub unsafe fn lock(&self) {
29967ef6 23 assert_eq!(self.locked.replace(true), false, "cannot recursively acquire mutex");
abe05a73
XL
24 }
25
26 #[inline]
27 pub unsafe fn unlock(&self) {
29967ef6 28 self.locked.set(false);
abe05a73
XL
29 }
30
31 #[inline]
32 pub unsafe fn try_lock(&self) -> bool {
29967ef6 33 self.locked.replace(true) == false
abe05a73
XL
34 }
35
36 #[inline]
dfeec247 37 pub unsafe fn destroy(&self) {}
abe05a73 38}