mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Make spinlocks faster (take two)
This change is green on x86 and arm test fleet.
This commit is contained in:
parent
02e1cbcd00
commit
59692b0882
14 changed files with 122 additions and 79 deletions
|
@ -38,8 +38,12 @@
|
|||
* @see pthread_spin_init
|
||||
*/
|
||||
errno_t pthread_spin_lock(pthread_spinlock_t *spin) {
|
||||
while (atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire)) {
|
||||
pthread_pause_np();
|
||||
for (;;) {
|
||||
if (!atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire))
|
||||
break;
|
||||
for (;;)
|
||||
if (!atomic_load_explicit(&spin->_lock, memory_order_relaxed))
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue