123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_spin_trylock (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;
- switch ((long)
- PTE_ATOMIC_COMPARE_EXCHANGE (&(s->interlock),
- PTE_SPIN_LOCKED,
- PTE_SPIN_UNLOCKED))
- {
- case PTE_SPIN_UNLOCKED:
- return 0;
- case PTE_SPIN_LOCKED:
- return EBUSY;
- case PTE_SPIN_USE_MUTEX:
- return pthread_mutex_trylock (&(s->u.mutex));
- }
- return EINVAL;
- }
|