From 5fbe0aab3303bd800f878121c8ef4aba19b0115b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 4 Apr 2012 05:41:09 +0200 Subject: [PATCH] unix: move active checks out of core.c Move active checks out of core.c and into their respective compilation units: check, idle, prepare, timer. --- src/unix/check.c | 5 +++++ src/unix/core.c | 24 ++++++++++-------------- src/unix/idle.c | 5 +++++ src/unix/internal.h | 5 +++++ src/unix/prepare.c | 5 +++++ src/unix/timer.c | 10 +++++----- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/unix/check.c b/src/unix/check.c index 2584b3279..cc5d3c7e1 100644 --- a/src/unix/check.c +++ b/src/unix/check.c @@ -68,3 +68,8 @@ int uv_check_stop(uv_check_t* check) { return 0; } + + +int uv__check_active(const uv_check_t* handle) { + return ev_is_active(&handle->check_watcher); +} diff --git a/src/unix/core.c b/src/unix/core.c index a83079eaa..09987e992 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -340,20 +340,16 @@ void uv__req_init(uv_loop_t* loop, uv_req_t* req) { int uv_is_active(uv_handle_t* handle) { switch (handle->type) { - case UV_TIMER: - return ev_is_active(&((uv_timer_t*)handle)->timer_watcher); - - case UV_PREPARE: - return ev_is_active(&((uv_prepare_t*)handle)->prepare_watcher); - - case UV_CHECK: - return ev_is_active(&((uv_check_t*)handle)->check_watcher); - - case UV_IDLE: - return ev_is_active(&((uv_idle_t*)handle)->idle_watcher); - - default: - return 1; + case UV_CHECK: + return uv__check_active((uv_check_t*)handle); + case UV_IDLE: + return uv__idle_active((uv_idle_t*)handle); + case UV_PREPARE: + return uv__prepare_active((uv_prepare_t*)handle); + case UV_TIMER: + return uv__timer_active((uv_timer_t*)handle); + default: + return 1; } } diff --git a/src/unix/idle.c b/src/unix/idle.c index 0fab4db2b..bcefd6a10 100644 --- a/src/unix/idle.c +++ b/src/unix/idle.c @@ -67,3 +67,8 @@ int uv_idle_stop(uv_idle_t* idle) { return 0; } + + +int uv__idle_active(const uv_idle_t* handle) { + return ev_is_active(&handle->idle_watcher); +} diff --git a/src/unix/internal.h b/src/unix/internal.h index 4f14eb467..2f5f54cb3 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -139,6 +139,11 @@ void uv__udp_finish_close(uv_udp_t* handle); /* fs */ void uv__fs_event_destroy(uv_fs_event_t* handle); +int uv__check_active(const uv_check_t* handle); +int uv__idle_active(const uv_idle_t* handle); +int uv__prepare_active(const uv_prepare_t* handle); +int uv__timer_active(const uv_timer_t* handle); + #define UV__F_IPC (1 << 0) #define UV__F_NONBLOCK (1 << 1) int uv__make_socketpair(int fds[2], int flags); diff --git a/src/unix/prepare.c b/src/unix/prepare.c index 52417a5e9..59ddf8c23 100644 --- a/src/unix/prepare.c +++ b/src/unix/prepare.c @@ -67,3 +67,8 @@ int uv_prepare_stop(uv_prepare_t* prepare) { } return 0; } + + +int uv__prepare_active(const uv_prepare_t* handle) { + return ev_is_active(&handle->prepare_watcher); +} diff --git a/src/unix/timer.c b/src/unix/timer.c index fe33dd39e..e719c20e3 100644 --- a/src/unix/timer.c +++ b/src/unix/timer.c @@ -23,11 +23,6 @@ #include -static int uv__timer_active(const uv_timer_t* timer) { - return timer->flags & UV_TIMER_ACTIVE; -} - - static int uv__timer_repeating(const uv_timer_t* timer) { return timer->flags & UV_TIMER_REPEAT; } @@ -120,3 +115,8 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer) { assert(timer->type == UV_TIMER); return (int64_t)(1000 * timer->timer_watcher.repeat); } + + +int uv__timer_active(const uv_timer_t* timer) { + return timer->flags & UV_TIMER_ACTIVE; +}