From 64a1ea1aa97e5de174220f8de6815ede9fcfabac Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 8 Oct 2001 05:14:05 +0000 Subject: pthread_spin_trylock was not returning EBUSY on multi CPU machines. --- ChangeLog | 5 +++++ spin.c | 16 ++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ab8ab92..07b04a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2001-10-08 Ross Johnson + + * spin.c (pthread_spin_trylock): Was not returning + EBUSY for multi CPU machines. + 2001-08-24 Ross Johnson * condvar.c (pthread_cond_destroy): Remove cv element 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; -- cgit v1.2.3