condition variable signal/bcast need not wake unless there are waiters
authorRich Felker <dalias@aerifal.cx>
Sun, 7 Aug 2011 22:31:06 +0000 (18:31 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 7 Aug 2011 22:31:06 +0000 (18:31 -0400)
src/thread/pthread_cond_broadcast.c
src/thread/pthread_cond_signal.c

index 1d378c0..30f7f6d 100644 (file)
@@ -2,7 +2,7 @@
 
 int pthread_cond_broadcast(pthread_cond_t *c)
 {
-       c->_c_block = 0;
-       __wake(&c->_c_block, -1, 0);
+       if (a_swap(&c->_c_block, 0))
+               __wake(&c->_c_block, -1, 0);
        return 0;
 }
index 574f5c7..a021128 100644 (file)
@@ -2,7 +2,7 @@
 
 int pthread_cond_signal(pthread_cond_t *c)
 {
-       c->_c_block = 0;
-       __wake(&c->_c_block, 1, 0);
+       if (a_swap(&c->_c_block, 0));
+               __wake(&c->_c_block, 1, 0);
        return 0;
 }