]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/sgx/condvar.rs
d3e8165f3dfe7d818437d810308f2d5d36a6ca1f
[rust.git] / src / libstd / sys / sgx / condvar.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use sys::mutex::Mutex;
12 use time::Duration;
13
14 use super::waitqueue::{WaitVariable, WaitQueue, SpinMutex};
15
16 pub struct Condvar {
17     inner: SpinMutex<WaitVariable<()>>,
18 }
19
20 impl Condvar {
21     #[unstable(feature = "sgx_internals", issue = "0")] // FIXME: min_const_fn
22     pub const fn new() -> Condvar {
23         Condvar { inner: SpinMutex::new(WaitVariable::new(())) }
24     }
25
26     #[inline]
27     pub unsafe fn init(&mut self) {}
28
29     #[inline]
30     pub unsafe fn notify_one(&self) {
31         let _ = WaitQueue::notify_one(self.inner.lock());
32     }
33
34     #[inline]
35     pub unsafe fn notify_all(&self) {
36         let _ = WaitQueue::notify_all(self.inner.lock());
37     }
38
39     pub unsafe fn wait(&self, mutex: &Mutex) {
40         let guard = self.inner.lock();
41         mutex.unlock();
42         WaitQueue::wait(guard);
43         mutex.lock()
44     }
45
46     pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
47         panic!("timeout not supported in SGX");
48     }
49
50     #[inline]
51     pub unsafe fn destroy(&self) {}
52 }