Update.
authorUlrich Drepper <drepper@redhat.com>
Mon, 24 Feb 2003 09:23:15 +0000 (09:23 +0000)
committerUlrich Drepper <drepper@redhat.com>
Mon, 24 Feb 2003 09:23:15 +0000 (09:23 +0000)
* sysdeps/pthread/pthread_rwlock_rdlock.c: Likewise.
* sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
* sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
* sysdeps/pthread/pthread_rwlock_unlock.c: Likewise.
* sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.

12 files changed:
nptl/ChangeLog
nptl/DESIGN-rwlock.txt
nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
nptl/sysdeps/pthread/pthread_rwlock_unlock.c
nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S

index 487a2aa..93d70ad 100644 (file)
        Likewise.
        * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S: Likewise.
        * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+       * sysdeps/pthread/pthread_rwlock_rdlock.c: Likewise.
+       * sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
+       * sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
+       * sysdeps/pthread/pthread_rwlock_unlock.c: Likewise.
+       * sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.
 
 2003-02-23  Roland McGrath  <roland@redhat.com>
 
index 6262a7a..d97c084 100644 (file)
@@ -42,13 +42,12 @@ pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
         break;
 
     rwlock->nr_readers_queued++;
+    val = rwlock->readers_wakeup;
     lll_unlock(rwlock->lock);
 
-    futex_wait(&rwlock->readers_wakeup, 0)
+    futex_wait(&rwlock->readers_wakeup, val)
 
     lll_lock(rwlock->lock);
-    if (!--rwlock->nr_readers_queued)
-        rwlock->readers_wakeup = 0;
   }
   rwlock->readers++;
   lll_unlock(rwlock->lock);
@@ -73,13 +72,13 @@ pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
        break;
 
     rwlock->nr_writers_queued++;
+    val = rwlock->writer_wakeup;
     lll_unlock(rwlock->lock);
 
-    futex_wait(&rwlock->writer_wakeup, 0);
+    futex_wait(&rwlock->writer_wakeup, val);
 
     lll_lock(rwlock->lock);
     rwlock->nr_writers_queued--;
-    rwlock->writer_wakeup = 0;
   }
   rwlock->writer = pthread_self();
   lll_unlock(rwlock->lock);
@@ -96,11 +95,11 @@ pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
 
   if (!rwlock->readers) {
     if (rwlock->nr_writers_queued) {
-      rwlock->writer_wakeup = 1;
+      ++rwlock->writer_wakeup;
       futex_wake(&rwlock->writer_wakeup, 1);
     } else
       if (rwlock->nr_readers_queued) {
-        rwlock->readers_wakeup = 1;
+        ++rwlock->readers_wakeup;
         futex_wake(&rwlock->readers_wakeup, MAX_INT);
       }
   }
index b556ccf..197af9c 100644 (file)
@@ -72,18 +72,16 @@ __pthread_rwlock_rdlock (rwlock)
          break;
        }
 
+      int waitval = rwlock->__data.__readers_wakeup;
+
       /* Free the lock.  */
       lll_mutex_unlock (rwlock->__data.__lock);
 
       /* Wait for the writer to finish.  */
-      lll_futex_wait (&rwlock->__data.__readers_wakeup, 0);
+      lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval);
 
       /* Get the lock.  */
       lll_mutex_lock (rwlock->__data.__lock);
-
-      /* To start over again, remove the thread from the reader list.  */
-      if (--rwlock->__data.__nr_readers_queued == 0)
-       rwlock->__data.__readers_wakeup = 0;
     }
 
   /* We are done, free the lock.  */
index 4f7b78d..fb63825 100644 (file)
@@ -105,19 +105,18 @@ pthread_rwlock_timedrdlock (rwlock, abstime)
          break;
        }
 
+      int waitval = rwlock->__data.__readers_wakeup;
+
       /* Free the lock.  */
       lll_mutex_unlock (rwlock->__data.__lock);
 
       /* Wait for the writer to finish.  */
-      result = lll_futex_timed_wait (&rwlock->__data.__readers_wakeup, 0, &rt);
+      result = lll_futex_timed_wait (&rwlock->__data.__readers_wakeup,
+                                    waitval, &rt);
 
       /* Get the lock.  */
       lll_mutex_lock (rwlock->__data.__lock);
 
-      /* To start over again, remove the thread from the reader list.  */
-      if (--rwlock->__data.__nr_readers_queued == 0)
-       rwlock->__data.__readers_wakeup = 0;
-
       /* Did the futex call time out?  */
       if (result == -ETIMEDOUT)
        {
index 4c0dc38..0715f83 100644 (file)
@@ -95,18 +95,20 @@ pthread_rwlock_timedwrlock (rwlock, abstime)
          break;
        }
 
+      int waitval = rwlock->__data.__writer_wakeup;
+
       /* Free the lock.  */
       lll_mutex_unlock (rwlock->__data.__lock);
 
       /* Wait for the writer or reader(s) to finish.  */
-      result = lll_futex_timed_wait (&rwlock->__data.__writer_wakeup, 0, &rt);
+      result = lll_futex_timed_wait (&rwlock->__data.__writer_wakeup,
+                                    waitval, &rt);
 
       /* Get the lock.  */
       lll_mutex_lock (rwlock->__data.__lock);
 
       /* To start over again, remove the thread from the writer list.  */
       --rwlock->__data.__nr_writers_queued;
-      rwlock->__data.__writer_wakeup = 0;
 
       /* Did the futex call time out?  */
       if (result == -ETIMEDOUT)
index 325007e..6e0c92b 100644 (file)
@@ -35,12 +35,12 @@ int __pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
     {
       if (rwlock->__data.__nr_writers_queued)
        {
-         rwlock->__data.__writer_wakeup = 1;
+         ++rwlock->__data.__writer_wakeup;
          lll_futex_wake(&rwlock->__data.__writer_wakeup, 1);
        }
       else
        {
-         rwlock->__data.__readers_wakeup = 1;
+         ++rwlock->__data.__readers_wakeup;
          lll_futex_wake(&rwlock->__data.__readers_wakeup, INT_MAX);
        }
     }
index 024b671..03c37a1 100644 (file)
@@ -63,18 +63,19 @@ __pthread_rwlock_wrlock (rwlock)
          break;
        }
 
+      int waitval = rwlock->__data.__writer_wakeup;
+
       /* Free the lock.  */
       lll_mutex_unlock (rwlock->__data.__lock);
 
       /* Wait for the writer or reader(s) to finish.  */
-      lll_futex_wait (&rwlock->__data.__writer_wakeup, 0);
+      lll_futex_wait (&rwlock->__data.__writer_wakeup, waitval);
 
       /* Get the lock.  */
       lll_mutex_lock (rwlock->__data.__lock);
 
       /* To start over again, remove the thread from the writer list.  */
       --rwlock->__data.__nr_writers_queued;
-      rwlock->__data.__writer_wakeup = 0;
     }
 
   /* We are done, free the lock.  */
index 47ae4fa..f8f2e06 100644 (file)
@@ -45,7 +45,6 @@ __pthread_rwlock_rdlock:
        pushl   %ebx
 
        xorl    %esi, %esi
-       xorl    %edx, %edx
        movl    12(%esp), %ebx
 
        /* Get the lock.  */
@@ -70,6 +69,8 @@ __pthread_rwlock_rdlock:
 3:     incl    READERS_QUEUED(%ebx)
        je      4f
 
+       movl    READERS_WAKEUP(%ebx), %edx
+
        LOCK
 #if MUTEX == 0
        decl    (%ebx)
@@ -97,8 +98,6 @@ __pthread_rwlock_rdlock:
        jne     12f
 
 13:    decl    READERS_QUEUED(%ebx)
-       jne     2b
-       movl    $0, READERS_WAKEUP(%ebx)
        jmp     2b
 
 5:     xorl    %ecx, %ecx
@@ -118,7 +117,12 @@ __pthread_rwlock_rdlock:
        popl    %esi
        ret
 
-1:     movl    %ebx, %ecx
+1:
+#if MUTEX == 0
+       movl    %ebx, %ecx
+#else
+       leal    MUTEX(%ebx), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     2b
 
@@ -128,7 +132,12 @@ __pthread_rwlock_rdlock:
        movl    $EDEADLK, %ecx
        jmp     9b
 
-6:     movl    %ebx, %eax
+6:
+#if MUTEX == 0
+       movl    %ebx, %eax
+#else
+       leal    MUTEX(%ebx), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     7b
 
@@ -142,11 +151,21 @@ __pthread_rwlock_rdlock:
        movl    $EAGAIN, %ecx
        jmp     9b
 
-10:    movl    %ebx, %eax
+10:
+#if MUTEX == 0
+       movl    %ebx, %eax
+#else
+       leal    MUTEX(%ebx), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     11b
 
-12:    movl    %ebx, %ecx
+12:
+#if MUTEX == 0
+       movl    %ebx, %ecx
+#else
+       leal    MUTEX(%ebx), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     13b
        .size   __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
index b275b8b..2e47350 100644 (file)
@@ -79,6 +79,8 @@ pthread_rwlock_timedrdlock:
        incl    READERS_QUEUED(%ebp)
        je      4f
 
+       movl    READERS_WAKEUP(%ebp), %esi
+
        LOCK
 #if MUTEX == 0
        decl    (%ebp)
@@ -110,9 +112,9 @@ pthread_rwlock_timedrdlock:
        /* Futex call.  */
        movl    %ecx, (%esp)    /* Store relative timeout.  */
        movl    %edx, 4(%esp)
+       movl    %esi, %edx
        xorl    %ecx, %ecx      /* movl $FUTEX_WAIT, %ecx */
        movl    %esp, %esi
-       movl    %ecx, %edx
        leal    READERS_WAKEUP(%ebp), %ebx
        movl    $SYS_futex, %eax
        ENTER_KERNEL
@@ -130,12 +132,12 @@ pthread_rwlock_timedrdlock:
        testl   %eax, %eax
        jne     12f
 
-13:    cmpl    $-ETIMEDOUT, %ecx
-       je      18f
-       decl    READERS_QUEUED(%ebp)
+13:    decl    READERS_QUEUED(%ebp)
+       cmpl    $-ETIMEDOUT, %edx
        jne     2b
-       movl    $0, READERS_WAKEUP(%ebp)
-       jmp     2b
+
+18:    movl    $ETIMEDOUT, %ecx
+       jmp     9f
 
 
 5:     xorl    %ecx, %ecx
@@ -158,7 +160,12 @@ pthread_rwlock_timedrdlock:
        popl    %esi
        ret
 
-1:     movl    %ebp, %ecx
+1:
+#if MUTEX == 0
+       movl    %ebp, %ecx
+#else
+       leal    MUTEX(%ebp), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     2b
 
@@ -167,7 +174,12 @@ pthread_rwlock_timedrdlock:
        movl    $EDEADLK, %ecx
        jmp     9b
 
-6:     movl    %ebp, %eax
+6:
+#if MUTEX == 0
+       movl    %ebp, %eax
+#else
+       leal    MUTEX(%ebp), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     7b
 
@@ -181,20 +193,27 @@ pthread_rwlock_timedrdlock:
        movl    $EAGAIN, %ecx
        jmp     9b
 
-10:    movl    %ebp, %eax
+10:
+#if MUTEX == 0
+       movl    %ebp, %eax
+#else
+       leal    MUTEX(%ebp), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     11b
 
-12:    movl    %ebx, %ecx
+12:
+#if MUTEX == 0
+       movl    %ebp, %ecx
+#else
+       leal    MUTEX(%ebp), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     13b
 
-16:    movl    $-ETIMEDOUT, %ecx
+16:    movl    $-ETIMEDOUT, %edx
        jmp     17b
 
-18:    movl    $ETIMEDOUT, %ecx
-       jmp     9b
-
 19:    movl    $EINVAL, %ecx
        jmp     9b
        .size   pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock
index ec8f4b9..fd9747e 100644 (file)
@@ -77,6 +77,8 @@ pthread_rwlock_timedwrlock:
        incl    WRITERS_QUEUED(%ebp)
        je      4f
 
+       movl    WRITERS_WAKEUP(%ebp), %esi
+
        LOCK
 #if MUTEX == 0
        decl    (%ebp)
@@ -108,9 +110,9 @@ pthread_rwlock_timedwrlock:
        /* Futex call.  */
        movl    %ecx, (%esp)    /* Store relative timeout.  */
        movl    %edx, 4(%esp)
+       movl    %esi, %edx
        xorl    %ecx, %ecx      /* movl $FUTEX_WAIT, %ecx */
        movl    %esp, %esi
-       movl    %ecx, %edx
        leal    WRITERS_WAKEUP(%ebp), %ebx
        movl    $SYS_futex, %eax
        ENTER_KERNEL
@@ -128,11 +130,12 @@ pthread_rwlock_timedwrlock:
        testl   %eax, %eax
        jne     12f
 
-13:    cmpl    $-ETIMEDOUT, %ecx
-       je      18f
-       decl    WRITERS_QUEUED(%ebp)
-       movl    $0, WRITERS_WAKEUP(%ebp)
-       jmp     2b
+13:    decl    WRITERS_QUEUED(%ebp)
+       cmpl    $-ETIMEDOUT, %edx
+       jne     2b
+
+18:    movl    $ETIMEDOUT, %ecx
+       jmp     9f
 
 
 5:     xorl    %ecx, %ecx
@@ -155,7 +158,12 @@ pthread_rwlock_timedwrlock:
        popl    %esi
        ret
 
-1:     movl    %ebp, %ecx
+1:
+#if MUTEX == 0
+       movl    %ebp, %ecx
+#else
+       leal    MUTEX(%ebp), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     2b
 
@@ -164,7 +172,12 @@ pthread_rwlock_timedwrlock:
 20:    movl    $EDEADLK, %ecx
        jmp     9b
 
-6:     movl    %ebp, %eax
+6:
+#if MUTEX == 0
+       movl    %ebp, %eax
+#else
+       leal    MUTEX(%ebp), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     7b
 
@@ -173,20 +186,27 @@ pthread_rwlock_timedwrlock:
        movl    $EAGAIN, %ecx
        jmp     9b
 
-10:    movl    %ebp, %eax
+10:
+#if MUTEX == 0
+       movl    %ebp, %eax
+#else
+       leal    MUTEX(%ebp), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     11b
 
-12:    movl    %ebx, %ecx
+12:
+#if MUTEX == 0
+       movl    %ebp, %ecx
+#else
+       leal    MUTEX(%ebp), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     13b
 
-16:    movl    $-ETIMEDOUT, %ecx
+16:    movl    $-ETIMEDOUT, %edx
        jmp     17b
 
-18:    movl    $ETIMEDOUT, %ecx
-       jmp     9b
-
 19:    movl    $EINVAL, %ecx
        jmp     9b
        .size   pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock
index 8296046..bb5f8d1 100644 (file)
@@ -42,8 +42,6 @@ __pthread_rwlock_unlock:
        pushl   %esi
        pushl   %edi
 
-       xorl    %esi, %esi
-       xorl    %edx, %edx
        movl    16(%esp), %edi
 
        /* Get the lock.  */
@@ -64,20 +62,21 @@ __pthread_rwlock_unlock:
 
 5:     movl    $0, WRITER(%edi)
 
-       movl    $0x7fffffff, %edx
-       leal    READERS_WAKEUP(%edi), %ebx
        movl    $1, %ecx
-       leal    WRITERS_WAKEUP(%edi), %eax
-       cmpl    $0, WRITERS_QUEUED(%edi)
-#ifdef HAVE_CMOV
-       cmovnel %ecx, %edx
-       cmovnel %eax, %ebx
-#else
-       je      0f
+       leal    WRITERS_WAKEUP(%edi), %ebx
        movl    %ecx, %edx
-       movl    %eax, %ebx
-0:
-#endif
+       cmpl    $0, WRITERS_QUEUED(%edi)
+       jne     0f
+
+       /* If also no readers waiting nothing to do.  */
+       cmpl    $0, READERS_QUEUED(%edi)
+       je      6f
+
+       movl    $0x7fffffff, %edx
+       leal    READERS_WAKEUP(%edi), %ebx
+
+0:     incl    (%ebx)
+       xorl    %esi, %esi
        movl    $SYS_futex, %eax
        ENTER_KERNEL
 
@@ -95,11 +94,21 @@ __pthread_rwlock_unlock:
        popl    %ebx
        ret
 
-1:     movl    %edi, %ecx
+1:
+#if MUTEX == 0
+       movl    %edi, %ecx
+#else
+       leal    MUTEX(%edx), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     2b
 
-3:     movl    %edi, %eax
+3:
+#if MUTEX == 0
+       movl    %edi, %eax
+#else
+       leal    MUTEX(%edx), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     4b
 
index ff39609..080e663 100644 (file)
@@ -45,7 +45,6 @@ __pthread_rwlock_wrlock:
        pushl   %ebx
 
        xorl    %esi, %esi
-       xorl    %edx, %edx
        movl    12(%esp), %ebx
 
        /* Get the lock.  */
@@ -68,6 +67,8 @@ __pthread_rwlock_wrlock:
 3:     incl    WRITERS_QUEUED(%ebx)
        je      4f
 
+       movl    WRITERS_WAKEUP(%ebx), %edx
+
        LOCK
 #if MUTEX == 0
        decl    (%ebx)
@@ -95,7 +96,6 @@ __pthread_rwlock_wrlock:
        jne     12f
 
 13:    decl    WRITERS_QUEUED(%ebx)
-       movl    $0, WRITERS_WAKEUP(%ebx)
        jmp     2b
 
 5:     xorl    %ecx, %ecx
@@ -115,7 +115,12 @@ __pthread_rwlock_wrlock:
        popl    %esi
        ret
 
-1:     movl    %ebx, %ecx
+1:
+#if MUTEX == 0
+       movl    %ebx, %ecx
+#else
+       leal    MUTEX(%ebx), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     2b
 
@@ -124,7 +129,12 @@ __pthread_rwlock_wrlock:
        movl    $EDEADLK, %ecx
        jmp     9b
 
-6:     movl    %ebx, %eax
+6:
+#if MUTEX == 0
+       movl    %ebx, %eax
+#else
+       leal    MUTEX(%ebx), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     7b
 
@@ -132,11 +142,21 @@ __pthread_rwlock_wrlock:
        movl    $EAGAIN, %ecx
        jmp     9b
 
-10:    movl    %ebx, %eax
+10:
+#if MUTEX == 0
+       movl    %ebx, %eax
+#else
+       leal    MUTEX(%ebx), %eax
+#endif
        call    __lll_mutex_unlock_wake
        jmp     11b
 
-12:    movl    %ebx, %ecx
+12:
+#if MUTEX == 0
+       movl    %ebx, %ecx
+#else
+       leal    MUTEX(%ebx), %ecx
+#endif
        call    __lll_mutex_lock_wait
        jmp     13b
        .size   __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock