From 073a48d6bf8705ca4a8e93920acdbe5c52f7ea5b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 17 May 2012 08:27:00 +0200 Subject: [PATCH] unix: back out new idle watcher for now Its semantics don't quite match what node.js expects. This breaks the stdio_over_pipes and shutdown_close_pipe tests but that can't be helped. --- include/uv-private/uv-unix.h | 1 + src/unix/core.c | 4 +++- src/unix/loop.c | 42 +++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index 5f94ca58..4d4c8036 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -198,6 +198,7 @@ typedef struct { /* UV_IDLE */ #define UV_IDLE_PRIVATE_FIELDS \ + ev_idle idle_watcher; \ uv_idle_cb idle_cb; \ ngx_queue_t queue; diff --git a/src/unix/core.c b/src/unix/core.c index 72bc7957..6d33d188 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -204,14 +204,16 @@ static void uv__poll(uv_loop_t* loop, int block) { static int uv__run(uv_loop_t* loop) { + /* if (!uv__has_pending_handles(loop) && !uv__has_active_reqs(loop)) uv__run_idle(loop); + */ uv__run_pending(loop); uv__run_prepare(loop); if (uv__has_active_handles(loop) || uv__has_active_reqs(loop)) - uv__poll(loop, 0); + uv__poll(loop, 1); uv__run_check(loop); diff --git a/src/unix/loop.c b/src/unix/loop.c index aca2a889..f9b6eee9 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -109,7 +109,47 @@ void uv__loop_delete(uv_loop_t* loop) { void uv__##name##_close(uv_##name##_t* handle) { \ uv_##name##_stop(handle); \ } -X(idle, UV_IDLE) +/*X(idle, UV_IDLE)*/ X(check, UV_CHECK) X(prepare, UV_PREPARE) #undef X + + +static void uv__idle(EV_P_ ev_idle* w, int revents) { + uv_idle_t* handle = container_of(w, uv_idle_t, idle_watcher); + handle->idle_cb(handle, 0); +} + + +int uv_idle_init(uv_loop_t* loop, uv_idle_t* handle) { + uv__handle_init(loop, (uv_handle_t*)handle, UV_IDLE); + ev_idle_init(&handle->idle_watcher, uv__idle); + loop->counters.idle_init++; + handle->idle_cb = NULL; + return 0; +} + + +int uv_idle_start(uv_idle_t* handle, uv_idle_cb cb) { + if (uv__is_active(handle)) return 0; + ngx_queue_insert_head(&handle->loop->idle_handles, &handle->queue); + ev_idle_start(handle->loop->ev, &handle->idle_watcher); + uv__handle_start(handle); + handle->idle_cb = cb; + return 0; +} + + +int uv_idle_stop(uv_idle_t* handle) { + if (!uv__is_active(handle)) return 0; + ngx_queue_remove(&handle->queue); + ev_idle_stop(handle->loop->ev, &handle->idle_watcher); + uv__handle_stop(handle); + handle->idle_cb = NULL; + return 0; +} + + +void uv__idle_close(uv_idle_t* handle) { + uv_idle_stop(handle); +}