Skip to content

Commit d33271c

Browse files
committed
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.
1 parent 1b79747 commit d33271c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/ioq.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,11 @@ _noinline
279279
static uintptr_t ioq_slot_wait(struct ioqq *ioqq, ioq_slot *slot, uintptr_t value) {
280280
uintptr_t ret;
281281

282-
// Try spinning a few times before blocking
282+
// Try spinning a few times (with exponential backoff) before blocking
283283
_nounroll
284-
for (int i = 0; i < 10; ++i) {
285-
// Exponential backoff
284+
for (int i = 1; i < 1024; i *= 2) {
286285
_nounroll
287-
for (int j = 0; j < (1 << i); ++j) {
286+
for (int j = 0; j < i; ++j) {
288287
spin_loop();
289288
}
290289

0 commit comments

Comments
 (0)