Created
August 4, 2011 01:02
-
-
Save mrkn/1124278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/thread_pthread.c b/thread_pthread.c | |
index d3c2609..0ac4f42 100644 | |
--- a/thread_pthread.c | |
+++ b/thread_pthread.c | |
@@ -103,10 +103,23 @@ native_cond_destroy(pthread_cond_t *cond) | |
} | |
} | |
+/* | |
+ * In OS X 10.7 (Lion), pthread_cond_signal and pthread_cond_broadcast return | |
+ * EAGAIN after retrying 8192 times. You can see them in the following page: | |
+ * | |
+ * http://www.opensource.apple.com/source/Libc/Libc-763.11/pthreads/pthread_cond.c | |
+ * | |
+ * The following native_cond_signal and native_cond_broadcast functions | |
+ * need to retrying until pthread functions don't return EAGAIN. | |
+ */ | |
+ | |
static void | |
native_cond_signal(pthread_cond_t *cond) | |
{ | |
- int r = pthread_cond_signal(cond); | |
+ int r; | |
+ do { | |
+ r = pthread_cond_signal(cond); | |
+ } while (r == EAGAIN); | |
if (r != 0) { | |
rb_bug_errno("pthread_cond_signal", r); | |
} | |
@@ -115,7 +128,10 @@ native_cond_signal(pthread_cond_t *cond) | |
static void | |
native_cond_broadcast(pthread_cond_t *cond) | |
{ | |
- int r = pthread_cond_broadcast(cond); | |
+ int r; | |
+ do { | |
+ r = pthread_cond_broadcast(cond); | |
+ } while (r == EAGAIN); | |
if (r != 0) { | |
rb_bug_errno("native_cond_broadcast", r); | |
} | |
@@ -490,7 +506,7 @@ use_cached_thread(rb_thread_t *th) | |
} | |
} | |
if (result) { | |
- pthread_cond_signal(entry->cond); | |
+ native_cond_signal(entry->cond); | |
} | |
pthread_mutex_unlock(&thread_cache_lock); | |
} | |
@@ -603,7 +619,7 @@ ubf_pthread_cond_signal(void *ptr) | |
{ | |
rb_thread_t *th = (rb_thread_t *)ptr; | |
thread_debug("ubf_pthread_cond_signal (%p)\n", (void *)th); | |
- pthread_cond_signal(&th->native_thread_data.sleep_cond); | |
+ native_cond_signal(&th->native_thread_data.sleep_cond); | |
} | |
#if !defined(__CYGWIN__) && !defined(__SYMBIAN32__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
8192, not 8196 in the initial comment block :)