From 3360034b7814d90503098700fc18bf07c47838c3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 2 Nov 2014 02:32:07 +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-cond-brdcast.c (__pthread_cond_broadcast): Unlock cond->__lock while waking the queued thread. --- sysdeps/generic/pt-cond-brdcast.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sysdeps') diff --git a/sysdeps/generic/pt-cond-brdcast.c b/sysdeps/generic/pt-cond-brdcast.c index ad44f83..f2a2987 100644 --- a/sysdeps/generic/pt-cond-brdcast.c +++ b/sysdeps/generic/pt-cond-brdcast.c @@ -28,10 +28,15 @@ __pthread_cond_broadcast (pthread_cond_t *cond) struct __pthread *wakeup; __pthread_spin_lock (&cond->__lock); - __pthread_dequeuing_iterate (cond->__queue, wakeup) - __pthread_wakeup (wakeup); - - cond->__queue = NULL; + while ((wakeup = cond->__queue)) + { + __pthread_dequeue (wakeup); + __pthread_spin_unlock (&cond->__lock); + /* Wake it up without spin held, so it may have a chance to really + preempt us */ + __pthread_wakeup (wakeup); + __pthread_spin_lock (&cond->__lock); + } __pthread_spin_unlock (&cond->__lock); return 0; -- cgit v1.2.3