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:
parent
52166fe286
commit
e4342f6c45
2 changed files with 21 additions and 11 deletions
18
spin.h
Normal file
18
spin.h
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue