* 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.
This commit is contained in:
Ulrich Drepper 2003-02-24 09:23:15 +00:00
parent 3724f268b1
commit 18a535792b
12 changed files with 171 additions and 80 deletions

View File

@ -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>

View 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);
}
}

View 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. */

View 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)
{

View 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)

View 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);
}
}

View 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. */

View 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

View 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

View 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

View 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 $1, %ecx
leal WRITERS_WAKEUP(%edi), %ebx
movl %ecx, %edx
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
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
movl %ecx, %edx
movl %eax, %ebx
0:
#endif
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

View 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