Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1205)

Unified Diff: src/untrusted/pthread/nc_rwlock.c

Issue 951583004: Implement pthread_rwlock functions for NaCl newlib (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/threads/rwlock_test.c » ('j') | tests/threads/rwlock_test.c » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/untrusted/pthread/nc_rwlock.c
diff --git a/src/untrusted/pthread/nc_rwlock.c b/src/untrusted/pthread/nc_rwlock.c
index a824f02a6b3c4e33429d8b903b07be3b0f0094c1..760f2d5fc422c76533eb9a02fd930bb8fa2cb228 100644
--- a/src/untrusted/pthread/nc_rwlock.c
+++ b/src/untrusted/pthread/nc_rwlock.c
@@ -13,9 +13,8 @@
* in the case of recursive read lock (see read_lock_available)). See:
* http://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock
*
- * The thundering herd problem is avoided by only waking a single
- * waiter (either a single writer or a single reader) when the
- * lock is released.
+ * The thundering herd problem is avoided (at least for waiting writers)
+ * by only waking a single writer at a time.
*/
#include <errno.h>
@@ -239,8 +238,11 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) {
/* Wake a waiting writer if there is one. */
rc = pthread_cond_signal(&rwlock->write_possible);
} else {
- /* Otherwise wake a waiting reader. */
- rc = pthread_cond_signal(&rwlock->read_possible);
+ /*
+ * Otherwise wake all waiting readers. All of them should be able
+ * to make progress now that the write lock is no longer held.
+ */
+ rc = pthread_cond_broadcast(&rwlock->read_possible);
}
} else {
if (rwlock->reader_count == 0) {
« no previous file with comments | « no previous file | tests/threads/rwlock_test.c » ('j') | tests/threads/rwlock_test.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698