Skip to content

Commit

Permalink
Auto merge of #99505 - joboet:futex_once, r=thomcc
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bors committed Oct 8, 2022
2 parents 846e2a3 + 1dcab8d commit 46c3b38
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 46c3b38

Please sign in to comment.