Commit 41c260fa authored by Jason Madden's avatar Jason Madden

Simplify the loop definition: always define the _periodic_signal_checker timer member.

parent f8d6deae
......@@ -162,10 +162,11 @@ libuv
- Using negative timeouts may behave differently from libev.
- libuv blocks delivery of all signals, so signals are handled using
an (arbitrary) 1 second timer. This means that signal handling
an (arbitrary) 0.3 second timer. This means that signal handling
will be delayed by up to that amount, and that the longest the
event loop can sleep in the operating system's ``poll`` call is
that amount.
that amount. Note that this is what gevent does for libev on
Windows too.
- libuv only supports one io watcher per file descriptor, whereas
libev and gevent have always supported many watchers using
......
......@@ -216,7 +216,7 @@ static void gevent_run_callbacks(struct ev_loop *_loop, void *watcher, int reven
GIL_RELEASE;
}
#if defined(_WIN32)
/* This is only used on Win32 */
static void gevent_periodic_signal_check(struct ev_loop *_loop, void *watcher, int revents) {
GIL_DECLARE;
......@@ -225,6 +225,5 @@ static void gevent_periodic_signal_check(struct ev_loop *_loop, void *watcher, i
GIL_RELEASE;
}
#endif /* _WIN32 */
#endif /* Py_PYTHON_H */
......@@ -36,8 +36,8 @@ static void gevent_handle_error(struct PyGeventLoopObject* loop, PyObject* conte
struct PyGeventCallbackObject;
static void gevent_call(struct PyGeventLoopObject* loop, struct PyGeventCallbackObject* cb);
#if defined(_WIN32)
static void gevent_periodic_signal_check(struct ev_loop *, void *, int);
#endif
static void gevent_noop(struct ev_loop *_loop, void *watcher, int revents) {
}
static void gevent_noop(struct ev_loop *_loop, void *watcher, int revents) { }
/* Only used on Win32 */
static void gevent_periodic_signal_check(struct ev_loop *, void *, int);
......@@ -264,17 +264,16 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
cdef libev.ev_prepare _prepare
cdef public list _callbacks
cdef libev.ev_timer _timer0
#ifdef _WIN32
# We'll only actually start this timer if we're on Windows,
# but it doesn't hurt to compile it in on all platforms.
cdef libev.ev_timer _periodic_signal_checker
#endif
def __init__(self, object flags=None, object default=None, size_t ptr=0):
cdef unsigned int c_flags
cdef object old_handler = None
libev.ev_prepare_init(&self._prepare, <void*>gevent_run_callbacks)
#ifdef _WIN32
libev.ev_timer_init(&self._periodic_signal_checker, <void*>gevent_periodic_signal_check, 0.3, 0.3)
#endif
libev.ev_timer_init(&self._periodic_signal_checker, <void*>gevent_periodic_signal_check,
0.3, 0.3)
libev.ev_timer_init(&self._timer0, <void*>gevent_noop, 0.0, 0.0)
if ptr:
self._ptr = <libev.ev_loop*>ptr
......@@ -291,10 +290,9 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
self._ptr = libev.gevent_ev_default_loop(c_flags)
if not self._ptr:
raise SystemError("ev_default_loop(%s) failed" % (c_flags, ))
#ifdef _WIN32
if sys.platform == "win32":
libev.ev_timer_start(self._ptr, &self._periodic_signal_checker)
libev.ev_unref(self._ptr)
#endif
else:
self._ptr = libev.ev_loop_new(c_flags)
if not self._ptr:
......@@ -324,11 +322,9 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
if libev.ev_is_active(&self._prepare):
libev.ev_ref(self._ptr)
libev.ev_prepare_stop(self._ptr, &self._prepare)
#ifdef _WIN32
if libev.ev_is_active(&self._periodic_signal_checker):
libev.ev_ref(self._ptr)
libev.ev_timer_stop(self._ptr, &self._periodic_signal_checker)
#endif
def destroy(self):
global _default_loop_destroyed
......
......@@ -124,12 +124,13 @@ class loop(AbstractLoop):
# XXX: Perhaps we could optimize this to notice when there are other
# timers in the loop and start/stop it then. When we have a callback
# scheduled, this should also be the same and unnecessary?
# libev does takes this basic approach on Windows.
self._signal_idle = ffi.new("uv_timer_t*")
libuv.uv_timer_init(self._ptr, self._signal_idle)
self._signal_idle.data = self._handle_to_self
libuv.uv_timer_start(self._signal_idle, libuv.python_check_callback,
1000,
1000)
300,
300)
libuv.uv_unref(self._signal_idle)
def _run_callbacks(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment