Browse Source

deps: upgrade libuv to 4fe1916

v0.8.7-release
Ben Noordhuis 13 years ago
parent
commit
879d329a5a
  1. 17
      deps/uv/include/uv-private/uv-unix.h
  2. 110
      deps/uv/src/unix/linux/inotify.c
  3. 2
      deps/uv/src/unix/loop.c
  4. 6
      deps/uv/src/unix/thread.c
  5. 2
      deps/uv/test/benchmark-sizes.c
  6. 32
      deps/uv/test/test-fs-event.c
  7. 2
      deps/uv/test/test-list.h

17
deps/uv/include/uv-private/uv-unix.h

@ -105,11 +105,8 @@ struct uv__io_s {
#if __linux__ #if __linux__
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS \ # define UV_LOOP_PRIVATE_PLATFORM_FIELDS \
/* RB_HEAD(uv__inotify_watchers, uv_fs_event_s) */ \
struct uv__inotify_watchers { \
struct uv_fs_event_s* rbh_root; \
} inotify_watchers; \
uv__io_t inotify_read_watcher; \ uv__io_t inotify_read_watcher; \
void* inotify_watchers; \
int inotify_fd; int inotify_fd;
#elif defined(PORT_SOURCE_FILE) #elif defined(PORT_SOURCE_FILE)
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS \ # define UV_LOOP_PRIVATE_PLATFORM_FIELDS \
@ -277,15 +274,11 @@ struct uv__io_s {
#if defined(__linux__) #if defined(__linux__)
#define UV_FS_EVENT_PRIVATE_FIELDS \ #define UV_FS_EVENT_PRIVATE_FIELDS \
/* RB_ENTRY(fs_event_s) node; */ \ ngx_queue_t watchers; \
struct { \
struct uv_fs_event_s* rbe_left; \
struct uv_fs_event_s* rbe_right; \
struct uv_fs_event_s* rbe_parent; \
int rbe_color; \
} node; \
uv_fs_event_cb cb; \ uv_fs_event_cb cb; \
int fd; \ int wd; \
void* pad0; \
void* pad1; \
#elif defined(__APPLE__) \ #elif defined(__APPLE__) \
|| defined(__FreeBSD__) \ || defined(__FreeBSD__) \

110
deps/uv/src/unix/linux/inotify.c

@ -33,6 +33,18 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
struct watcher_list {
RB_ENTRY(watcher_list) entry;
ngx_queue_t watchers;
char* path;
int wd;
};
struct watcher_root {
struct watcher_list* rbh_root;
};
#define CAST(p) ((struct watcher_root*)(p))
/* Don't look aghast, this is exactly how glibc's basename() works. */ /* Don't look aghast, this is exactly how glibc's basename() works. */
static char* basename_r(const char* path) { static char* basename_r(const char* path) {
@ -41,14 +53,15 @@ static char* basename_r(const char* path) {
} }
static int compare_watchers(const uv_fs_event_t* a, const uv_fs_event_t* b) { static int compare_watchers(const struct watcher_list* a,
if (a->fd < b->fd) return -1; const struct watcher_list* b) {
if (a->fd > b->fd) return 1; if (a->wd < b->wd) return -1;
if (a->wd > b->wd) return 1;
return 0; return 0;
} }
RB_GENERATE_STATIC(uv__inotify_watchers, uv_fs_event_s, node, compare_watchers) RB_GENERATE_STATIC(watcher_root, watcher_list, entry, compare_watchers)
static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int revents); static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int revents);
@ -95,36 +108,27 @@ static int init_inotify(uv_loop_t* loop) {
} }
static void add_watcher(uv_fs_event_t* handle) { static struct watcher_list* find_watcher(uv_loop_t* loop, int wd) {
RB_INSERT(uv__inotify_watchers, &handle->loop->inotify_watchers, handle); struct watcher_list w;
} w.wd = wd;
return RB_FIND(watcher_root, CAST(&loop->inotify_watchers), &w);
static uv_fs_event_t* find_watcher(uv_loop_t* loop, int wd) {
uv_fs_event_t handle;
handle.fd = wd;
return RB_FIND(uv__inotify_watchers, &loop->inotify_watchers, &handle);
}
static void remove_watcher(uv_fs_event_t* handle) {
RB_REMOVE(uv__inotify_watchers, &handle->loop->inotify_watchers, handle);
} }
static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int events) { static void uv__inotify_read(uv_loop_t* loop, uv__io_t* dummy, int events) {
const struct uv__inotify_event* e; const struct uv__inotify_event* e;
uv_fs_event_t* handle; struct watcher_list* w;
const char* filename; uv_fs_event_t* h;
ngx_queue_t* q;
const char* path;
ssize_t size; ssize_t size;
const char *p; const char *p;
/* needs to be large enough for sizeof(inotify_event) + strlen(filename) */ /* needs to be large enough for sizeof(inotify_event) + strlen(filename) */
char buf[4096]; char buf[4096];
while (1) { while (1) {
do { do
size = read(loop->inotify_fd, buf, sizeof buf); size = read(loop->inotify_fd, buf, sizeof(buf));
}
while (size == -1 && errno == EINTR); while (size == -1 && errno == EINTR);
if (size == -1) { if (size == -1) {
@ -144,17 +148,20 @@ static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int events) {
if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY)) if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY))
events |= UV_RENAME; events |= UV_RENAME;
handle = find_watcher(loop, e->wd); w = find_watcher(loop, e->wd);
if (handle == NULL) if (w == NULL)
continue; /* Handle has already been closed. */ continue; /* Stale event, no watchers left. */
/* inotify does not return the filename when monitoring a single file /* inotify does not return the filename when monitoring a single file
* for modifications. Repurpose the filename for API compatibility. * for modifications. Repurpose the filename for API compatibility.
* I'm not convinced this is a good thing, maybe it should go. * I'm not convinced this is a good thing, maybe it should go.
*/ */
filename = e->len ? (const char*) (e + 1) : basename_r(handle->filename); path = e->len ? (const char*) (e + 1) : basename_r(w->path);
handle->cb(handle, filename, events, 0); ngx_queue_foreach(q, &w->watchers) {
h = ngx_queue_data(q, uv_fs_event_t, watchers);
h->cb(h, path, events, 0);
}
} }
} }
} }
@ -162,9 +169,10 @@ static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int events) {
int uv_fs_event_init(uv_loop_t* loop, int uv_fs_event_init(uv_loop_t* loop,
uv_fs_event_t* handle, uv_fs_event_t* handle,
const char* filename, const char* path,
uv_fs_event_cb cb, uv_fs_event_cb cb,
int flags) { int flags) {
struct watcher_list* w;
int events; int events;
int wd; int wd;
@ -184,26 +192,50 @@ int uv_fs_event_init(uv_loop_t* loop,
| UV__IN_MOVED_FROM | UV__IN_MOVED_FROM
| UV__IN_MOVED_TO; | UV__IN_MOVED_TO;
wd = uv__inotify_add_watch(loop->inotify_fd, filename, events); wd = uv__inotify_add_watch(loop->inotify_fd, path, events);
if (wd == -1) return uv__set_sys_error(loop, errno); if (wd == -1)
return uv__set_sys_error(loop, errno);
w = find_watcher(loop, wd);
if (w)
goto no_insert;
w = malloc(sizeof(*w) + strlen(path) + 1);
if (w == NULL)
return uv__set_sys_error(loop, ENOMEM);
w->wd = wd;
w->path = strcpy((char*)(w + 1), path);
ngx_queue_init(&w->watchers);
RB_INSERT(watcher_root, CAST(&loop->inotify_watchers), w);
no_insert:
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
uv__handle_start(handle); /* FIXME shouldn't start automatically */ uv__handle_start(handle); /* FIXME shouldn't start automatically */
handle->filename = strdup(filename); ngx_queue_insert_tail(&w->watchers, &handle->watchers);
handle->filename = w->path;
handle->cb = cb; handle->cb = cb;
handle->fd = wd; handle->wd = wd;
add_watcher(handle);
return 0; return 0;
} }
void uv__fs_event_close(uv_fs_event_t* handle) { void uv__fs_event_close(uv_fs_event_t* handle) {
uv__inotify_rm_watch(handle->loop->inotify_fd, handle->fd); struct watcher_list* w;
remove_watcher(handle);
handle->fd = -1; w = find_watcher(handle->loop, handle->wd);
assert(w != NULL);
free(handle->filename); handle->wd = -1;
handle->filename = NULL; handle->filename = NULL;
uv__handle_stop(handle); uv__handle_stop(handle);
ngx_queue_remove(&handle->watchers);
if (ngx_queue_empty(&w->watchers)) {
/* No watchers left for this path. Clean up. */
RB_REMOVE(watcher_root, CAST(&handle->loop->inotify_watchers), w);
uv__inotify_rm_watch(handle->loop->inotify_fd, w->wd);
free(w);
}
} }

2
deps/uv/src/unix/loop.c

@ -54,7 +54,7 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
eio_channel_init(&loop->uv_eio_channel, loop); eio_channel_init(&loop->uv_eio_channel, loop);
#if __linux__ #if __linux__
RB_INIT(&loop->inotify_watchers); loop->inotify_watchers = NULL;
loop->inotify_fd = -1; loop->inotify_fd = -1;
#endif #endif
#if HAVE_PORTS_FS #if HAVE_PORTS_FS

6
deps/uv/src/unix/thread.c

@ -78,7 +78,7 @@ int uv_mutex_trylock(uv_mutex_t* mutex) {
r = pthread_mutex_trylock(mutex); r = pthread_mutex_trylock(mutex);
if (r && r != EAGAIN) if (r && r != EBUSY && r != EAGAIN)
abort(); abort();
if (r) if (r)
@ -119,7 +119,7 @@ int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) {
r = pthread_rwlock_tryrdlock(rwlock); r = pthread_rwlock_tryrdlock(rwlock);
if (r && r != EAGAIN) if (r && r != EBUSY && r != EAGAIN)
abort(); abort();
if (r) if (r)
@ -146,7 +146,7 @@ int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) {
r = pthread_rwlock_trywrlock(rwlock); r = pthread_rwlock_trywrlock(rwlock);
if (r && r != EAGAIN) if (r && r != EBUSY && r != EAGAIN)
abort(); abort();
if (r) if (r)

2
deps/uv/test/benchmark-sizes.c

@ -36,7 +36,9 @@ BENCHMARK_IMPL(sizes) {
LOGF("uv_idle_t: %u bytes\n", (unsigned int) sizeof(uv_idle_t)); LOGF("uv_idle_t: %u bytes\n", (unsigned int) sizeof(uv_idle_t));
LOGF("uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t)); LOGF("uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t));
LOGF("uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t)); LOGF("uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t));
LOGF("uv_fs_event_t: %u bytes\n", (unsigned int) sizeof(uv_fs_event_t));
LOGF("uv_process_t: %u bytes\n", (unsigned int) sizeof(uv_process_t)); LOGF("uv_process_t: %u bytes\n", (unsigned int) sizeof(uv_process_t));
LOGF("uv_poll_t: %u bytes\n", (unsigned int) sizeof(uv_poll_t)); LOGF("uv_poll_t: %u bytes\n", (unsigned int) sizeof(uv_poll_t));
LOGF("uv_loop_t: %u bytes\n", (unsigned int) sizeof(uv_loop_t));
return 0; return 0;
} }

32
deps/uv/test/test-fs-event.c

@ -85,6 +85,13 @@ static void close_cb(uv_handle_t* handle) {
close_cb_called++; close_cb_called++;
} }
static void fail_cb(uv_fs_event_t* handle,
const char* path,
int events,
int status) {
ASSERT(0 && "fail_cb called");
}
static void fs_event_cb_dir(uv_fs_event_t* handle, const char* filename, static void fs_event_cb_dir(uv_fs_event_t* handle, const char* filename,
int events, int status) { int events, int status) {
++fs_event_cb_called; ++fs_event_cb_called;
@ -159,6 +166,13 @@ static void timer_cb_touch(uv_timer_t* timer, int status) {
timer_cb_touch_called++; timer_cb_touch_called++;
} }
static void timer_cb_watch_twice(uv_timer_t* handle, int status) {
uv_fs_event_t* handles = handle->data;
uv_close((uv_handle_t*) (handles + 0), NULL);
uv_close((uv_handle_t*) (handles + 1), NULL);
uv_close((uv_handle_t*) handle, NULL);
}
TEST_IMPL(fs_event_watch_dir) { TEST_IMPL(fs_event_watch_dir) {
uv_fs_t fs_req; uv_fs_t fs_req;
uv_loop_t* loop = uv_default_loop(); uv_loop_t* loop = uv_default_loop();
@ -225,6 +239,24 @@ TEST_IMPL(fs_event_watch_file) {
return 0; return 0;
} }
TEST_IMPL(fs_event_watch_file_twice) {
const char path[] = "test/fixtures/empty_file";
uv_fs_event_t watchers[2];
uv_timer_t timer;
uv_loop_t* loop;
loop = uv_default_loop();
timer.data = watchers;
ASSERT(0 == uv_fs_event_init(loop, watchers + 0, path, fail_cb, 0));
ASSERT(0 == uv_fs_event_init(loop, watchers + 1, path, fail_cb, 0));
ASSERT(0 == uv_timer_init(loop, &timer));
ASSERT(0 == uv_timer_start(&timer, timer_cb_watch_twice, 10, 0));
ASSERT(0 == uv_run(loop));
return 0;
}
TEST_IMPL(fs_event_watch_file_current_dir) { TEST_IMPL(fs_event_watch_file_current_dir) {
uv_timer_t timer; uv_timer_t timer;
uv_loop_t* loop; uv_loop_t* loop;

2
deps/uv/test/test-list.h

@ -158,6 +158,7 @@ TEST_DECLARE (fs_stat_missing_path)
TEST_DECLARE (fs_read_file_eof) TEST_DECLARE (fs_read_file_eof)
TEST_DECLARE (fs_event_watch_dir) TEST_DECLARE (fs_event_watch_dir)
TEST_DECLARE (fs_event_watch_file) TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_twice)
TEST_DECLARE (fs_event_watch_file_current_dir) TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_event_no_callback_on_close) TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_event_immediate_close) TEST_DECLARE (fs_event_immediate_close)
@ -396,6 +397,7 @@ TASK_LIST_START
TEST_ENTRY (fs_file_open_append) TEST_ENTRY (fs_file_open_append)
TEST_ENTRY (fs_event_watch_dir) TEST_ENTRY (fs_event_watch_dir)
TEST_ENTRY (fs_event_watch_file) TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_twice)
TEST_ENTRY (fs_event_watch_file_current_dir) TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_event_no_callback_on_close) TEST_ENTRY (fs_event_no_callback_on_close)
TEST_ENTRY (fs_event_immediate_close) TEST_ENTRY (fs_event_immediate_close)

Loading…
Cancel
Save