From 46d3992fea0690f81ed3924a0a13f3aecde809ae Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 2 Nov 2014 04:20:13 +0100 Subject: Wake up queued threads without spin lock held so that they may have a chance to actually preempt us. Otherwise they will merely immediately fail to acquire the spin lock, and thus preemption will have served no purpose. * sysdeps/generic/pt-rwlock-unlock.c (pthread_rwlock_unlock): Record an array of __pthread to wake while holding the lock, and wake them only after unlocking it. --- sysdeps/generic/pt-rwlock-unlock.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'sysdeps/generic') diff --git a/sysdeps/generic/pt-rwlock-unlock.c b/sysdeps/generic/pt-rwlock-unlock.c index 212cca5..dcf1d3e 100644 --- a/sysdeps/generic/pt-rwlock-unlock.c +++ b/sysdeps/generic/pt-rwlock-unlock.c @@ -65,15 +65,26 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock) if (rwlock->readerqueue) { - __pthread_dequeuing_iterate (rwlock->readerqueue, wakeup) - { - rwlock->readers ++; - __pthread_wakeup (wakeup); - } + unsigned n = 0; - rwlock->readerqueue = 0; + __pthread_queue_iterate (rwlock->readerqueue, wakeup) + n ++; - __pthread_spin_unlock (&rwlock->__lock); + { + struct __pthread *wakeups[n]; + unsigned i = 0; + + __pthread_dequeuing_iterate (rwlock->readerqueue, wakeup) + wakeups[i ++] = wakeup; + + rwlock->readers += n; + rwlock->readerqueue = 0; + + __pthread_spin_unlock (&rwlock->__lock); + + for (i = 0; i < n; i ++) + __pthread_wakeup (wakeups[i]); + } return 0; } -- cgit v1.2.3