about summary refs log tree commit diff
path: root/linuxthreads/spinlock.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-07-19 06:24:30 +0000
committerUlrich Drepper <drepper@redhat.com>2000-07-19 06:24:30 +0000
commit056f707c8618062023a79fdbc6ec19ac482c63dd (patch)
treefe3f8fffc0c85a938dd077474827d1f8c3bf6ec6 /linuxthreads/spinlock.h
parenta48297fdf310f0bf0fb29df1e185dd5f1561c1c1 (diff)
downloadglibc-056f707c8618062023a79fdbc6ec19ac482c63dd.tar.gz
glibc-056f707c8618062023a79fdbc6ec19ac482c63dd.tar.xz
glibc-056f707c8618062023a79fdbc6ec19ac482c63dd.zip
Update.
	* spinlock.h (__pthread_alt_trylock): Fix code used if no
	compare&swap is available.
Diffstat (limited to 'linuxthreads/spinlock.h')
-rw-r--r--linuxthreads/spinlock.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/linuxthreads/spinlock.h b/linuxthreads/spinlock.h
index 17efd183cd..703b72d65e 100644
--- a/linuxthreads/spinlock.h
+++ b/linuxthreads/spinlock.h
@@ -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