]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/sgx/condvar.rs
f9a76f0baf51a383ef5c18ce02b3c01befd17b55
[rust.git] / src / libstd / sys / sgx / condvar.rs
1 use crate::sys::mutex::Mutex;
2 use crate::time::Duration;
3
4 use super::waitqueue::{WaitVariable, WaitQueue, SpinMutex};
5
6 pub struct Condvar {
7     inner: SpinMutex<WaitVariable<()>>,
8 }
9
10 impl Condvar {
11     pub const fn new() -> Condvar {
12         Condvar { inner: SpinMutex::new(WaitVariable::new(())) }
13     }
14
15     #[inline]
16     pub unsafe fn init(&mut self) {}
17
18     #[inline]
19     pub unsafe fn notify_one(&self) {
20         let _ = WaitQueue::notify_one(self.inner.lock());
21     }
22
23     #[inline]
24     pub unsafe fn notify_all(&self) {
25         let _ = WaitQueue::notify_all(self.inner.lock());
26     }
27
28     pub unsafe fn wait(&self, mutex: &Mutex) {
29         let guard = self.inner.lock();
30         mutex.unlock();
31         WaitQueue::wait(guard);
32         mutex.lock()
33     }
34
35     pub unsafe fn wait_timeout(&self, mutex: &Mutex, _dur: Duration) -> bool {
36         mutex.unlock(); // don't hold the lock while panicking
37         panic!("timeout not supported in SGX");
38     }
39
40     #[inline]
41     pub unsafe fn destroy(&self) {}
42 }