diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-02-03 11:02:00 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-02-03 11:02:00 -0500 |
commit | d33271ccc835e79e945d06185e09fda4c3c3e2c5 (patch) | |
tree | 274a70a28d0e6abf6070f49d4b98c3429ecc25ed /src | |
parent | 1b79747ef9ae07a4d6b51e1d155b2e314f8e7692 (diff) | |
download | bfs-d33271ccc835e79e945d06185e09fda4c3c3e2c5.tar.xz |
ioq: Rewrite the spin loop to avoid a warning
With some GCC versions, --enable-ubsan leads to this warning:
src/ioq.c: In function ‘ioq_slot_wait’:
src/ioq.c:287:17: warning: ignoring loop annotation
287 | for (int j = 0; j < (1 << i); ++j) {
| ^~~
presumably due to UBSan rewriting the shift to check for overflow. Work
around this by precomputing the iteration count.
Diffstat (limited to 'src')
-rw-r--r-- | src/ioq.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -279,12 +279,11 @@ _noinline static uintptr_t ioq_slot_wait(struct ioqq *ioqq, ioq_slot *slot, uintptr_t value) { uintptr_t ret; - // Try spinning a few times before blocking + // Try spinning a few times (with exponential backoff) before blocking _nounroll - for (int i = 0; i < 10; ++i) { - // Exponential backoff + for (int i = 1; i < 1024; i *= 2) { _nounroll - for (int j = 0; j < (1 << i); ++j) { + for (int j = 0; j < i; ++j) { spin_loop(); } |