int _pthread_spin_lock(pthread_spinlock_t *lock) { struct pthread *curthread = _get_curthread(); struct pthread_spinlock *lck; int ret, count; if (lock == NULL || (lck = *lock) == NULL) ret = EINVAL; else { count = SPIN_COUNT; while ((ret = THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock)) != 0) { while (lck->s_lock.m_owner) { if (!_thr_is_smp) { _pthread_yield(); } else { CPU_SPINWAIT; if (--count <= 0) { count = SPIN_COUNT; _pthread_yield(); } } } } ret = 0; } return (ret); }
int _pthread_spin_lock(pthread_spinlock_t *lock) { struct pthread *curthread; struct pthread_spinlock *lck; int count; if (lock == NULL) return (EINVAL); lck = *lock == THR_PSHARED_PTR ? __thr_pshared_offpage(lock, 0) : *lock; if (lck == NULL) return (EINVAL); curthread = _get_curthread(); count = SPIN_COUNT; while (THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock) != 0) { while (lck->s_lock.m_owner) { if (!_thr_is_smp) { _pthread_yield(); } else { CPU_SPINWAIT; if (--count <= 0) { count = SPIN_COUNT; _pthread_yield(); } } } } return (0); }
int _pthread_spin_trylock(pthread_spinlock_t *lock) { struct pthread_spinlock *lck; if (lock == NULL || *lock == NULL) return (EINVAL); lck = *lock == THR_PSHARED_PTR ? __thr_pshared_offpage(lock, 0) : *lock; if (lck == NULL) return (EINVAL); return (THR_UMUTEX_TRYLOCK(_get_curthread(), &lck->s_lock)); }
int _pthread_spin_trylock(pthread_spinlock_t *lock) { struct pthread *curthread = _get_curthread(); struct pthread_spinlock *lck; int ret; if (lock == NULL || (lck = *lock) == NULL) ret = EINVAL; else ret = THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock); return (ret); }