From dd3126575193dae16e5f9cc7e4c2b9155edc68dc Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 4 Apr 2012 05:23:18 +0200 Subject: [PATCH] unix: move check code from core.c to check.c --- config-unix.mk | 1 + src/unix/check.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ src/unix/core.c | 50 ---------------------------------- uv.gyp | 1 + 4 files changed, 72 insertions(+), 50 deletions(-) create mode 100644 src/unix/check.c diff --git a/config-unix.mk b/config-unix.mk index 16e5e825..2dbbea58 100644 --- a/config-unix.mk +++ b/config-unix.mk @@ -29,6 +29,7 @@ CPPFLAGS += -D_FILE_OFFSET_BITS=64 OBJS += src/unix/async.o OBJS += src/unix/cares.o +OBJS += src/unix/check.o OBJS += src/unix/core.o OBJS += src/unix/dl.o OBJS += src/unix/error.o diff --git a/src/unix/check.c b/src/unix/check.c new file mode 100644 index 00000000..2584b327 --- /dev/null +++ b/src/unix/check.c @@ -0,0 +1,70 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "internal.h" + + +static void uv__check(EV_P_ ev_check* w, int revents) { + uv_check_t* check = container_of(w, uv_check_t, check_watcher); + + if (check->check_cb) { + check->check_cb(check, 0); + } +} + + +int uv_check_init(uv_loop_t* loop, uv_check_t* check) { + uv__handle_init(loop, (uv_handle_t*)check, UV_CHECK); + loop->counters.check_init++; + + ev_check_init(&check->check_watcher, uv__check); + check->check_cb = NULL; + + return 0; +} + + +int uv_check_start(uv_check_t* check, uv_check_cb cb) { + int was_active = ev_is_active(&check->check_watcher); + + check->check_cb = cb; + + ev_check_start(check->loop->ev, &check->check_watcher); + + if (!was_active) { + ev_unref(check->loop->ev); + } + + return 0; +} + + +int uv_check_stop(uv_check_t* check) { + int was_active = ev_is_active(&check->check_watcher); + + ev_check_stop(check->loop->ev, &check->check_watcher); + + if (was_active) { + ev_ref(check->loop->ev); + } + + return 0; +} diff --git a/src/unix/core.c b/src/unix/core.c index 3c176abf..2e9e5336 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -338,55 +338,6 @@ void uv__req_init(uv_loop_t* loop, uv_req_t* req) { } - -static void uv__check(EV_P_ ev_check* w, int revents) { - uv_check_t* check = container_of(w, uv_check_t, check_watcher); - - if (check->check_cb) { - check->check_cb(check, 0); - } -} - - -int uv_check_init(uv_loop_t* loop, uv_check_t* check) { - uv__handle_init(loop, (uv_handle_t*)check, UV_CHECK); - loop->counters.check_init++; - - ev_check_init(&check->check_watcher, uv__check); - check->check_cb = NULL; - - return 0; -} - - -int uv_check_start(uv_check_t* check, uv_check_cb cb) { - int was_active = ev_is_active(&check->check_watcher); - - check->check_cb = cb; - - ev_check_start(check->loop->ev, &check->check_watcher); - - if (!was_active) { - ev_unref(check->loop->ev); - } - - return 0; -} - - -int uv_check_stop(uv_check_t* check) { - int was_active = ev_is_active(&check->check_watcher); - - ev_check_stop(check->loop->ev, &check->check_watcher); - - if (was_active) { - ev_ref(check->loop->ev); - } - - return 0; -} - - static void uv__idle(EV_P_ ev_idle* w, int revents) { uv_idle_t* idle = container_of(w, uv_idle_t, idle_watcher); @@ -396,7 +347,6 @@ static void uv__idle(EV_P_ ev_idle* w, int revents) { } - int uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) { uv__handle_init(loop, (uv_handle_t*)idle, UV_IDLE); loop->counters.idle_init++; diff --git a/uv.gyp b/uv.gyp index 12a1d729..b2e5694c 100644 --- a/uv.gyp +++ b/uv.gyp @@ -182,6 +182,7 @@ 'include/uv-private/uv-unix.h', 'src/unix/async.c', 'src/unix/cares.c', + 'src/unix/check.c', 'src/unix/core.c', 'src/unix/dl.c', 'src/unix/eio/ecb.h',