]> git.lizzy.rs Git - rust.git/commit
Auto merge of #99505 - joboet:futex_once, r=thomcc
authorbors <bors@rust-lang.org>
Sat, 8 Oct 2022 03:50:07 +0000 (03:50 +0000)
committerbors <bors@rust-lang.org>
Sat, 8 Oct 2022 03:50:07 +0000 (03:50 +0000)
commita688a0305fad9219505a8f2576446510601bafe8
tree477131afebff9e0b0b8bbbd8476a01b5126d061e
parenteed7f2f58bd44d32ac30e48425eb4bede7ea84f7
parent5d0211dc0307f41476768cc482d2df92c639c38e
Auto merge of #99505 - joboet:futex_once, r=thomcc

std: use futex in `Once`

Now that we have efficient locks, let's optimize the rest of `sync` as well. This PR adds a futex-based implementation for `Once`, which drastically simplifies the implementation compared to the generic version, which is provided as fallback for platforms without futex (Windows only supports them on newer versions, so it uses the fallback for now).

Instead of storing a linked list of waiters, the new implementation adds another state (`QUEUED`), which is set when there are waiting threads. These now use `futex_wait` on that state and are woken by the running thread when it finishes and notices the `QUEUED` state, thereby avoiding unnecessary calls to `futex_wake_all`.