aboutsummaryrefslogtreecommitdiffstats
path: root/python/gevent/libev/libev.h
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-07-12 23:40:30 -0700
committerJames Taylor <user234683@users.noreply.github.com>2018-07-12 23:41:07 -0700
commitc3b9f8c4582882cd1f768b0727eca75475bb4f94 (patch)
tree5b4a1c693fd5b7416f1d5a75862e633502e77ca7 /python/gevent/libev/libev.h
parentfe9fe8257740529f5880693992e4eeca35c7ea3e (diff)
downloadyt-local-c3b9f8c4582882cd1f768b0727eca75475bb4f94.tar.lz
yt-local-c3b9f8c4582882cd1f768b0727eca75475bb4f94.tar.xz
yt-local-c3b9f8c4582882cd1f768b0727eca75475bb4f94.zip
track embedded python distribution
Diffstat (limited to 'python/gevent/libev/libev.h')
-rw-r--r--python/gevent/libev/libev.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/python/gevent/libev/libev.h b/python/gevent/libev/libev.h
new file mode 100644
index 0000000..657aaad
--- /dev/null
+++ b/python/gevent/libev/libev.h
@@ -0,0 +1,66 @@
+#if defined(LIBEV_EMBED)
+#include "ev.c"
+#else
+#include "ev.h"
+
+#ifndef _WIN32
+#include <signal.h>
+#endif
+
+#endif
+
+#ifndef _WIN32
+
+static struct sigaction libev_sigchld;
+/*
+ * Track the state of whether we have installed
+ * the libev sigchld handler specifically.
+ * If it's non-zero, libev_sigchld will be valid and set to the action
+ * that libev needs to do.
+ * If it's 1, we need to install libev_sigchld to make libev
+ * child handlers work (on request).
+ */
+static int sigchld_state = 0;
+
+static struct ev_loop* gevent_ev_default_loop(unsigned int flags)
+{
+ struct ev_loop* result;
+ struct sigaction tmp;
+
+ if (sigchld_state)
+ return ev_default_loop(flags);
+
+ // Request the old SIGCHLD handler
+ sigaction(SIGCHLD, NULL, &tmp);
+ // Get the loop, which will install a SIGCHLD handler
+ result = ev_default_loop(flags);
+ // XXX what if SIGCHLD received there?
+ // Now restore the previous SIGCHLD handler
+ sigaction(SIGCHLD, &tmp, &libev_sigchld);
+ sigchld_state = 1;
+ return result;
+}
+
+
+static void gevent_install_sigchld_handler(void) {
+ if (sigchld_state == 1) {
+ sigaction(SIGCHLD, &libev_sigchld, NULL);
+ sigchld_state = 2;
+ }
+}
+
+static void gevent_reset_sigchld_handler(void) {
+ // We could have any state at this point, depending on
+ // whether the default loop has been used. If it has,
+ // then always be in state 1 ("need to install)
+ if (sigchld_state) {
+ sigchld_state = 1;
+ }
+}
+
+#else
+
+#define gevent_ev_default_loop ev_default_loop
+static void gevent_install_sigchld_handler(void) { }
+
+#endif