* 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.
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>
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);
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);
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);
}
}
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. */
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)
{
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)
{
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);
}
}
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. */
pushl %ebx
xorl %esi, %esi
- xorl %edx, %edx
movl 12(%esp), %ebx
/* Get the lock. */
3: incl READERS_QUEUED(%ebx)
je 4f
+ movl READERS_WAKEUP(%ebx), %edx
+
LOCK
#if MUTEX == 0
decl (%ebx)
jne 12f
13: decl READERS_QUEUED(%ebx)
- jne 2b
- movl $0, READERS_WAKEUP(%ebx)
jmp 2b
5: xorl %ecx, %ecx
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
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
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
incl READERS_QUEUED(%ebp)
je 4f
+ movl READERS_WAKEUP(%ebp), %esi
+
LOCK
#if MUTEX == 0
decl (%ebp)
/* 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
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
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
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
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
incl WRITERS_QUEUED(%ebp)
je 4f
+ movl WRITERS_WAKEUP(%ebp), %esi
+
LOCK
#if MUTEX == 0
decl (%ebp)
/* 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
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
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
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
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
pushl %esi
pushl %edi
- xorl %esi, %esi
- xorl %edx, %edx
movl 16(%esp), %edi
/* Get the lock. */
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
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
pushl %ebx
xorl %esi, %esi
- xorl %edx, %edx
movl 12(%esp), %ebx
/* Get the lock. */
3: incl WRITERS_QUEUED(%ebx)
je 4f
+ movl WRITERS_WAKEUP(%ebx), %edx
+
LOCK
#if MUTEX == 0
decl (%ebx)
jne 12f
13: decl WRITERS_QUEUED(%ebx)
- movl $0, WRITERS_WAKEUP(%ebx)
jmp 2b
5: xorl %ecx, %ecx
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
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
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