wingo pushed a commit to branch wip-whippet
in repository guile.

commit fb927897aa3eb954ec7d1c0867782d98b8269cc8
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Tue Aug 5 16:03:50 2025 +0200

    Spinlock backs off exponentially
---
 src/spin.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/spin.h b/src/spin.h
index d650c3216..a2dd5ea6b 100644
--- a/src/spin.h
+++ b/src/spin.h
@@ -9,10 +9,10 @@ static inline void yield_for_spin(size_t spin_count) {
     __builtin_ia32_pause();
   else if (spin_count < 20)
     sched_yield();
-  else if (spin_count < 40)
-    usleep(0);
   else
-    usleep(1);
+    // initially 0 usec, then 2 usec after 32 spins, 4 usec after 64 spins, 6
+    // usec after 128 spins, and so on.
+    usleep((__builtin_clzll(20) - __builtin_clzll(spin_count)) << 1);
 }  
 
 #endif // SPIN_H

Reply via email to