Permalink
Browse files

lua-ev: Simplify watcher auto-stop

This removes special-purpose code and should make implementing ev_periodic
and any other watcher types that auto-stop easier.
  • Loading branch information...
1 parent 48d6941 commit 2bdc4c125f39ec1b655c53157fe58fef2dbb46ef @bdowning bdowning committed with Sep 1, 2010
Showing with 8 additions and 9 deletions.
  1. +6 −5 loop_lua_ev.c
  2. +2 −4 watcher_lua_ev.c
View
@@ -166,11 +166,12 @@ static void loop_start_watcher(lua_State* L, int loop_i, int watcher_i, int is_d
}
/**
- * Must be called aftert stop()ing a watcher, or after a non-repeating
- * timer expires. This is necessary so that the watcher is not
- * prematurely garbage collected, and if the watcher is "marked as a
- * daemon", then ev_ref() is called in order to "undo" what was done
- * in loop_add_watcher().
+ * Must be called aftert stop()ing a watcher, or after a watcher is
+ * automatically stopped (such as a non-repeating timer expiring).
+ * This is necessary so that the watcher is not prematurely garbage
+ * collected, and if the watcher is "marked as a daemon", then
+ * ev_ref() is called in order to "undo" what was done in
+ * loop_add_watcher().
*
* [-0, +0, m]
*/
View
@@ -145,11 +145,9 @@ static void watcher_cb(struct ev_loop *loop, void *watcher, int revents) {
/* STACK: <traceback>, <loop>, <watcher> */
- if ( revents & EV_TIMEOUT ) {
- ev_timer* timer = (ev_timer*)watcher;
-
+ if ( !ev_is_active(watcher) ) {
/* Must remove "stop"ed watcher from loop: */
- if ( timer->repeat == 0.0 ) loop_stop_watcher(L, -2, -1);
+ loop_stop_watcher(L, -2, -1);
}
lua_getfenv(L, -1);

0 comments on commit 2bdc4c1

Please sign in to comment.