summaryrefslogtreecommitdiff
path: root/spin.c
diff options
context:
space:
mode:
authorrpj <rpj>2001-10-08 05:14:05 +0000
committerrpj <rpj>2001-10-08 05:14:05 +0000
commit64a1ea1aa97e5de174220f8de6815ede9fcfabac (patch)
treeb4d8c2b5cbcdb4a8e7525154b3c187f79f1d46bb /spin.c
parentdcc0da53c266b2e6c3d54892919112ee0106c88c (diff)
pthread_spin_trylock was not returning EBUSY on multi CPU machines.
Diffstat (limited to 'spin.c')
-rw-r--r--spin.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/spin.c b/spin.c
index 458bb7a..d2d795f 100644
--- a/spin.c
+++ b/spin.c
@@ -284,17 +284,13 @@ pthread_spin_trylock(pthread_spinlock_t *lock)
}
}
- if ((_LONG) PTW32_SPIN_UNLOCKED ==
- InterlockedCompareExchange((_LPLONG) &(s->interlock),
- (_LONG) PTW32_SPIN_LOCKED,
- (_LONG) PTW32_SPIN_UNLOCKED ) )
- {
- return 0;
- }
-
- if (s->interlock == PTW32_SPIN_USE_MUTEX)
+ switch ((long) InterlockedCompareExchange((_LPLONG) &(s->interlock),
+ (_LONG) PTW32_SPIN_LOCKED,
+ (_LONG) PTW32_SPIN_UNLOCKED ))
{
- return pthread_mutex_trylock(&(s->u.mutex));
+ case PTW32_SPIN_UNLOCKED: return 0;
+ case PTW32_SPIN_LOCKED: return EBUSY;
+ case PTW32_SPIN_USE_MUTEX: return pthread_mutex_trylock(&(s->u.mutex));
}
return EINVAL;