about summary refs log tree commit diff
path: root/src/libstd/sys/sgx/condvar.rs
blob: 000bb19f2692ae8807551a5f7ba94271f41db1b8 (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
use crate::sys::mutex::Mutex;
use crate::time::Duration;

use super::waitqueue::{WaitVariable, WaitQueue, SpinMutex};

pub struct Condvar {
    inner: SpinMutex<WaitVariable<()>>,
}

impl Condvar {
    pub const fn new() -> Condvar {
        Condvar { inner: SpinMutex::new(WaitVariable::new(())) }
    }

    #[inline]
    pub unsafe fn init(&mut self) {}

    #[inline]
    pub unsafe fn notify_one(&self) {
        let _ = WaitQueue::notify_one(self.inner.lock());
    }

    #[inline]
    pub unsafe fn notify_all(&self) {
        let _ = WaitQueue::notify_all(self.inner.lock());
    }

    pub unsafe fn wait(&self, mutex: &Mutex) {
        let guard = self.inner.lock();
        mutex.unlock();
        WaitQueue::wait(guard);
        mutex.lock()
    }

    pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
        rtabort!("timeout not supported in SGX");
    }

    #[inline]
    pub unsafe fn destroy(&self) {}
}