(__pthread_alt_trylock): Fix code used if no compare&swap is available.
authordrepper <drepper>
Wed, 19 Jul 2000 06:24:02 +0000 (06:24 +0000)
committerdrepper <drepper>
Wed, 19 Jul 2000 06:24:02 +0000 (06:24 +0000)
linuxthreads/spinlock.h

index 17efd18..703b72d 100644 (file)
@@ -149,7 +149,19 @@ static inline int __pthread_alt_trylock (struct _pthread_fastlock * lock)
 #endif
 #if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
   {
-    return (testandset(&lock->__spinlock) ? EBUSY : 0);
+    int res = EBUSY;
+
+    if (testandset(&lock->__spinlock) == 0)
+      {
+       if (lock->__status == 0)
+         {
+           lock->__status = 1;
+           WRITE_MEMORY_BARRIER();
+           res = 0;
+         }
+       lock->__spinlock = 0;
+      }
+    return res;
   }
 #endif