Skip to content

Commit 633d46d

Browse files
committed
std: reimplement SGX thread joining to use Parker
1 parent 9678cec commit 633d46d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

library/std/src/sys/sgx/thread.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,36 @@ mod task_queue {
6565
/// execution. The signal is sent once all TLS destructors have finished at
6666
/// which point no new thread locals should be created.
6767
pub mod wait_notify {
68-
use super::super::waitqueue::{SpinMutex, WaitQueue, WaitVariable};
68+
use super::super::thread_parker::Parker;
69+
use crate::pin::Pin;
6970
use crate::sync::Arc;
7071

71-
pub struct Notifier(Arc<SpinMutex<WaitVariable<bool>>>);
72+
pub struct Notifier(Arc<Parker>);
7273

7374
impl Notifier {
7475
/// Notify the waiter. The waiter is either notified right away (if
7576
/// currently blocked in `Waiter::wait()`) or later when it calls the
7677
/// `Waiter::wait()` method.
7778
pub fn notify(self) {
78-
let mut guard = self.0.lock();
79-
*guard.lock_var_mut() = true;
80-
let _ = WaitQueue::notify_one(guard);
79+
Pin::new(&*self.0).unpark()
8180
}
8281
}
8382

84-
pub struct Waiter(Arc<SpinMutex<WaitVariable<bool>>>);
83+
pub struct Waiter(Arc<Parker>);
8584

8685
impl Waiter {
8786
/// Wait for a notification. If `Notifier::notify()` has already been
8887
/// called, this will return immediately, otherwise the current thread
8988
/// is blocked until notified.
9089
pub fn wait(self) {
91-
let guard = self.0.lock();
92-
if *guard.lock_var() {
93-
return;
94-
}
95-
WaitQueue::wait(guard, || {});
90+
// This is not actually `unsafe`, but it uses the `Parker` API,
91+
// which needs `unsafe` on some platforms.
92+
unsafe { Pin::new(&*self.0).park() }
9693
}
9794
}
9895

9996
pub fn new() -> (Notifier, Waiter) {
100-
let inner = Arc::new(SpinMutex::new(WaitVariable::new(false)));
97+
let inner = Arc::new(Parker::new_internal());
10198
(Notifier(inner.clone()), Waiter(inner))
10299
}
103100
}

0 commit comments

Comments
 (0)