summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/sgx/thread_parking.rs
blob: 0006cd4f1be2502a1bdc182be8fb37d3981effde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use super::abi::usercalls;
use crate::io::ErrorKind;
use crate::time::Duration;
use fortanix_sgx_abi::{EV_UNPARK, WAIT_INDEFINITE};

pub type ThreadId = fortanix_sgx_abi::Tcs;

pub use super::abi::thread::current;

pub fn park(_hint: usize) {
    usercalls::wait(EV_UNPARK, WAIT_INDEFINITE).unwrap();
}

pub fn park_timeout(dur: Duration, _hint: usize) {
    let timeout = u128::min(dur.as_nanos(), WAIT_INDEFINITE as u128 - 1) as u64;
    if let Err(e) = usercalls::wait(EV_UNPARK, timeout) {
        assert!(matches!(e.kind(), ErrorKind::TimedOut | ErrorKind::WouldBlock))
    }
}

pub fn unpark(tid: ThreadId, _hint: usize) {
    let _ = usercalls::send(EV_UNPARK, Some(tid));
}