aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nptl/ChangeLog5
-rw-r--r--nptl/DESIGN-rwlock.txt13
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_rdlock.c8
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c9
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c6
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_unlock.c4
-rw-r--r--nptl/sysdeps/pthread/pthread_rwlock_wrlock.c5
-rw-r--r--nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S33
-rw-r--r--nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S47
-rw-r--r--nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S48
-rw-r--r--nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S41
-rw-r--r--nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S32
12 files changed, 171 insertions, 80 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 487a2aab99..93d70ad970 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -11,6 +11,11 @@
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>
diff --git a/nptl/DESIGN-rwlock.txt b/nptl/DESIGN-rwlock.txt
index 6262a7a5b9..d97c084484 100644
--- a/nptl/DESIGN-rwlock.txt
+++ b/nptl/DESIGN-rwlock.txt
@@ -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);
}
}
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c b/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
index b556ccfd1c..197af9c970 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
@@ -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. */
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c b/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
index 4f7b78dfd2..fb6382544e 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
@@ -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)
{
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c b/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
index 4c0dc38348..0715f835af 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
@@ -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)
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_unlock.c b/nptl/sysdeps/pthread/pthread_rwlock_unlock.c
index 325007e5b3..6e0c92ba3f 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_unlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_unlock.c
@@ -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);
}
}
diff --git a/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c b/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
index 024b6711a9..03c37a1933 100644
--- a/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
+++ b/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
@@ -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. */
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
index 47ae4fa35a..f8f2e06b18 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
@@ -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
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
index b275b8b922..2e47350990 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
@@ -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
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
index ec8f4b9f6d..fd9747e8e6 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
@@ -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
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
index 829604662e..bb5f8d1bc8 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
@@ -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
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
index ff3960960d..080e66305e 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
@@ -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