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 eed7f2f + 5d0211d commit a688a03
Show file tree
Hide file tree
Showing 5 changed files with 483 additions and 289 deletions.
Loading

0 comments on commit a688a03

Please sign in to comment.