]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-se
authorMatthias Krüger <matthias.krueger@famsik.de>
Sat, 10 Dec 2022 08:24:40 +0000 (09:24 +0100)
committerGitHub <noreply@github.com>
Sat, 10 Dec 2022 08:24:40 +0000 (09:24 +0100)
commitae8794ce6a7180aa81c718172321ac704e94f342
treef7a0bae7048c5ddd5c79478b7d2b05a42bd23e7b
parenta000811405e6a3ca9b0b129c1177e78564e09666
parenta40d300100a5e48cb66f5261738496dbacf11f99
Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-se

Reimplement std's thread parker on top of events on SGX

Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used.

SGX enclaves have a per-thread event state, which allows waiting for and setting specific bits. This is already used by the current mutex implementation. The thread parker can however be much more efficient, as it only needs to store the `TCS` address of one thread. This address is stored in a state variable, which can also be set to indicate the thread was already notified.

`park_timeout` does not guard against spurious wakeups like the current condition variable does. This is allowed by the API of `Parker`, and I think it is better to let users handle these wakeups themselves as the guarding is quite expensive and might not be necessary.

`@jethrogb` as you wrote the initial SGX support for `std`, I assume you are the target maintainer? Could you help me test this, please? Lacking a x86_64 chip, I can't run SGX.
library/std/src/sys/sgx/mod.rs
library/std/src/sys_common/thread_parker/mod.rs