Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix: unref fs event watcher

Watchers were being ref-counted twice which wasn't harmful in itself but stopped
uv_unref() from working like you'd expect it to.
  • Loading branch information...
bnoordhuis committed Jan 2, 2012
1 parent 43e3ac5 commit 38fc6ad839734a3f76d2535b8f62d92e9cfef8c7
Showing with 27 additions and 1 deletion.
  1. +2 −0 src/unix/kqueue.c
  2. +2 −0 src/unix/linux.c
  3. +2 −0 src/unix/sunos.c
  4. +19 −1 test/test-fs-event.c
  5. +2 −0 test/test-list.h
@@ -43,10 +43,12 @@ static void uv__fs_event_start(uv_fs_event_t* handle) {
handle->fd,
EV_LIBUV_KQUEUE_HACK);
ev_io_start(handle->loop->ev, &handle->event_watcher);
ev_unref(handle->loop->ev);
}


static void uv__fs_event_stop(uv_fs_event_t* handle) {
ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, &handle->event_watcher);
}

@@ -283,12 +283,14 @@ int uv_fs_event_init(uv_loop_t* loop,

ev_io_init(&handle->read_watcher, uv__inotify_read, fd, EV_READ);
ev_io_start(loop->ev, &handle->read_watcher);
ev_unref(loop->ev);

return 0;
}


void uv__fs_event_destroy(uv_fs_event_t* handle) {
ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, &handle->read_watcher);
uv__close(handle->fd);
handle->fd = -1;
@@ -166,12 +166,14 @@ int uv_fs_event_init(uv_loop_t* loop,

ev_io_init(&handle->event_watcher, uv__fs_event_read, portfd, EV_READ);
ev_io_start(loop->ev, &handle->event_watcher);
ev_unref(loop->ev);

return 0;
}


void uv__fs_event_destroy(uv_fs_event_t* handle) {
ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, &handle->event_watcher);
uv__close(handle->fd);
handle->fd = -1;
@@ -282,7 +282,7 @@ static void timer_cb(uv_timer_t* handle, int status) {
ASSERT(status == 0);

r = uv_fs_event_init(handle->loop, &fs_event, ".", fs_event_fail, 0);
ASSERT(r != -1);
ASSERT(r == 0);

uv_close((uv_handle_t*)&fs_event, close_cb);
uv_close((uv_handle_t*)handle, close_cb);
@@ -308,3 +308,21 @@ TEST_IMPL(fs_event_immediate_close) {

return 0;
}


TEST_IMPL(fs_event_unref) {
uv_loop_t* loop;
int r;

loop = uv_default_loop();

r = uv_fs_event_init(loop, &fs_event, ".", fs_event_fail, 0);
ASSERT(r == 0);

uv_unref(loop);

r = uv_run(loop);
ASSERT(r == 0);

return 0;
}
@@ -112,6 +112,7 @@ TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_event_immediate_close)
TEST_DECLARE (fs_event_unref)
TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (fs_open_dir)
@@ -268,6 +269,7 @@ TASK_LIST_START
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_event_no_callback_on_close)
TEST_ENTRY (fs_event_immediate_close)
TEST_ENTRY (fs_event_unref)
TEST_ENTRY (fs_readdir_empty_dir)
TEST_ENTRY (fs_readdir_file)
TEST_ENTRY (fs_open_dir)

0 comments on commit 38fc6ad

Please sign in to comment.
You can’t perform that action at this time.