summary refs log tree commit diff
path: root/linuxthreads/spinlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'linuxthreads/spinlock.c')
-rw-r--r--linuxthreads/spinlock.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/linuxthreads/spinlock.c b/linuxthreads/spinlock.c
index 00a8691e5b..c8f8f71293 100644
--- a/linuxthreads/spinlock.c
+++ b/linuxthreads/spinlock.c
@@ -65,9 +65,11 @@ void internal_function __pthread_unlock(struct _pthread_fastlock * lock)
 
 again:
   oldstatus = lock->__status;
-  if (oldstatus == 1) {
-    /* No threads are waiting for this lock */
-    if (! compare_and_swap(&lock->__status, 1, 0, &lock->__spinlock))
+  if (oldstatus == 0 || oldstatus == 1) {
+    /* No threads are waiting for this lock.  Please note that we also
+       enter this case if the lock is not taken at all.  If this wouldn't
+       be done here we would crash further down.  */
+    if (! compare_and_swap(&lock->__status, oldstatus, 0, &lock->__spinlock))
       goto again;
     return;
   }