File 0001-io-move-poll-defines-to-internal-io.h.patch of Package ruby2.6
From 2f65378c9dd94aa28f6733dcd8d7aaee6b040cf3 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Wed, 5 Feb 2020 22:31:42 +0100
Subject: [PATCH 01/12] io: move poll defines to internal/io.h
USE_POLL is defined in io.c and thread.c with different semantic. Move
to internal/io.h and adjust the #ifdef to #if.
Also move POLL*_SETs. Define POLLERR_SET on Linux as well. This
genereates a little more code in rb_wait_for_single_fd compated to teh
case when it was defined to 0 but should not impact result. We need
POLLERR_SET defined for checking errors.
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
internal.h | 21 +++++++++++++++++++++
thread.c | 27 +--------------------------
2 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/internal.h b/internal.h
index e1e4cc057db1..4b7d5122b89e 100644
--- a/internal.h
+++ b/internal.h
@@ -128,6 +128,27 @@ extern "C" {
# define __msan_unpoison_string(x)
#endif
+/* non-Linux poll may not work on all FDs */
+#if defined(HAVE_POLL)
+# if defined(__linux__)
+# define USE_POLL 1
+# endif
+# if defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
+# define USE_POLL 1
+# endif
+#endif
+
+#ifndef USE_POLL
+# define USE_POLL 0
+#endif
+
+#if USE_POLL
+#define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN)
+#define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT)
+#define POLLEX_SET (POLLPRI)
+#define POLLERR_SET (POLLHUP | POLLERR)
+#endif
+
static inline void
poison_memory_region(const volatile void *ptr, size_t size)
{
diff --git a/thread.c b/thread.c
index eca14b4b4c1f..166db7a9a246 100644
--- a/thread.c
+++ b/thread.c
@@ -211,22 +211,6 @@ vm_living_thread_num(const rb_vm_t *vm)
return vm->living_thread_num;
}
-/*
- * poll() is supported by many OSes, but so far Linux is the only
- * one we know of that supports using poll() in all places select()
- * would work.
- */
-#if defined(HAVE_POLL)
-# if defined(__linux__)
-# define USE_POLL
-# endif
-# if defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
-# define USE_POLL
- /* FreeBSD does not set POLLOUT when POLLHUP happens */
-# define POLLERR_SET (POLLHUP | POLLERR)
-# endif
-#endif
-
static void
timeout_prepare(rb_hrtime_t **to, rb_hrtime_t *rel, rb_hrtime_t *end,
const struct timeval *timeout)
@@ -4054,16 +4038,7 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
return (int)rb_ensure(do_select, (VALUE)&set, select_set_free, (VALUE)&set);
}
-#ifdef USE_POLL
-
-/* The same with linux kernel. TODO: make platform independent definition. */
-#define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
-#define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
-#define POLLEX_SET (POLLPRI)
-
-#ifndef POLLERR_SET /* defined for FreeBSD for now */
-# define POLLERR_SET (0)
-#endif
+#if USE_POLL
/*
* returns a mask of events
--
2.23.0