1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-16 18:50:23 +02:00

Add helper for yielding in a spinlock

This commit is contained in:
Andy Wingo 2022-06-06 16:57:22 +02:00
parent 52166fe286
commit e4342f6c45
2 changed files with 21 additions and 11 deletions

18
spin.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef SPIN_H
#define SPIN_H
#include <sched.h>
#include <unistd.h>
static inline void yield_for_spin(size_t spin_count) {
if (spin_count < 10)
__builtin_ia32_pause();
else if (spin_count < 20)
sched_yield();
else if (spin_count < 40)
usleep(0);
else
usleep(1);
}
#endif // SPIN_H