diff options
author | Thiago Macieira <[email protected]> | 2023-05-22 22:57:11 -0700 |
---|---|---|
committer | Mårten Nordheim <[email protected]> | 2025-06-27 14:50:31 +0000 |
commit | b8c09d2e3b1eabf3f908ca9e0633a4430a976f89 (patch) | |
tree | c6ce987d72f95cab2c5f645dc0c376754e2ef1a3 /examples/opengl | |
parent | 4409a7c21399e3c602edeea62c409a18ef78148f (diff) |
We do it by using the sign bit of the atomic to indicate that there are
no waiters waiting. That way, the counter only becomes a zero when all
expected counters have counted down *and* there is at least one waiter.
That means the countDown() code remains unchanged. On x86-64 and
AArch64, there is no change in the number of instructions in the inline
portion of wait() either. The non-inline portion uses a
__atomic_and_fetch() instead of atomic_fetch_and() so compilers will
generate LOCK AND for x86-64, LDCLR for AArch64 ARMv8.1, and AMOAND.W
for RISC-V.
This is more efficient than the Standard Libraries's current
implementations, which use a separate, global atomic out of a pool,
meaning that there could be a collision between two or more latches (or
any other users std::atomic waiting, such as std::semaphore and
std::barrier). Coupled with the fact that we futexWait() on the actual
latch's address (something libc++ can't / won't do), this implementation
should be overall much more efficient.
Change-Id: Ib5ce7a497e034ebabb2cfffd1761b02a44d548d3
Reviewed-by: Mårten Nordheim <[email protected]>
Diffstat (limited to 'examples/opengl')
0 files changed, 0 insertions, 0 deletions