1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <atomic.h>
- #include "pthreadP.h"
- #define SPIN_LOCK_READS_BETWEEN_CMPXCHG 1000
- int
- pthread_spin_lock (pthread_spinlock_t *lock)
- {
-
- if (atomic_exchange_acq (lock, 1) == 0)
- return 0;
- do
- {
-
- if (SPIN_LOCK_READS_BETWEEN_CMPXCHG >= 0)
- {
- int wait = SPIN_LOCK_READS_BETWEEN_CMPXCHG;
- while (*lock != 0 && wait > 0)
- --wait;
- }
- else
- {
- while (*lock != 0)
- ;
- }
- }
- while (atomic_compare_and_exchange_val_acq (lock, 1, 0) != 0);
- return 0;
- }
|