1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_spin_lock (pthread_spinlock_t * lock)
- {
- register pthread_spinlock_t s;
- if (NULL == lock || NULL == *lock)
- {
- return (EINVAL);
- }
- if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
- {
- int result;
- if ((result = pte_spinlock_check_need_init (lock)) != 0)
- {
- return (result);
- }
- }
- s = *lock;
- while ( PTE_SPIN_LOCKED ==
- PTE_ATOMIC_COMPARE_EXCHANGE (&(s->interlock),
- PTE_SPIN_LOCKED,
- PTE_SPIN_UNLOCKED))
- {
- }
- if (s->interlock == PTE_SPIN_LOCKED)
- {
- return 0;
- }
- else if (s->interlock == PTE_SPIN_USE_MUTEX)
- {
- return pthread_mutex_lock (&(s->u.mutex));
- }
- return EINVAL;
- }
|