summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-24 19:19:01 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-24 19:19:01 +0000
commit0a77fd04b7ee902d3542b12986731a5b4d3e6d51 (patch)
tree12b05fc37d63dc66e5bb54304c106eac0b191a19 /thread.c
parent5bd4283f77ba1bbaf72b365e9d9e24b7abd7bd49 (diff)
thread_pthread.c: use eventfd instead of pipe on Linux
Based on r64478, any regular user creating more than 1024 pipes on Linux will end up with tiny pipes with only a single page capacity. So avoid wasting user resources and use lighter eventfd on Linux. [ruby-core:88563] [Misc #15011] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/thread.c b/thread.c
index 9757f9c..34a8daf 100644
--- a/thread.c
+++ b/thread.c
@@ -398,6 +398,10 @@ ubf_sigwait(void *ignore)
# define BUSY_WAIT_SIGNALS (0)
#endif
+#ifndef USE_EVENTFD
+# define USE_EVENTFD (0)
+#endif
+
#if THREAD_DEBUG
static int debug_mutex_initialized = 1;
static rb_nativethread_lock_t debug_mutex;
@@ -4271,9 +4275,12 @@ async_bug_fd(const char *mesg, int errno_arg, int fd)
static int
consume_communication_pipe(int fd)
{
-#define CCP_READ_BUFF_SIZE 1024
+#if USE_EVENTFD
+ uint64_t buff[1];
+#else
/* buffer can be shared because no one refers to them. */
- static char buff[CCP_READ_BUFF_SIZE];
+ static char buff[1024];
+#endif
ssize_t result;
int ret = FALSE; /* for rb_sigwait_sleep */
@@ -4289,7 +4296,7 @@ consume_communication_pipe(int fd)
result = read(fd, buff, sizeof(buff));
if (result > 0) {
ret = TRUE;
- if (result < (ssize_t)sizeof(buff)) {
+ if (USE_EVENTFD || result < (ssize_t)sizeof(buff)) {
return ret;
}
}