diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-08-20 19:20:41 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-08-20 19:29:58 +0400 |
commit | 0844e2359bc6b5974db9ec5a8065561ffa87cdcc (patch) | |
tree | fbe8070bf9b1e833a0c0e618441fa519837d47f1 /deps | |
parent | be3a77bd428612dc7c8b6bd0f76e51ef277f4fb0 (diff) |
deps: upgrade libuv to 012cbda
Diffstat (limited to 'deps')
-rw-r--r-- | deps/uv/include/uv.h | 48 | ||||
-rw-r--r-- | deps/uv/src/fs-poll.c | 149 | ||||
-rw-r--r-- | deps/uv/src/unix/cygwin.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/freebsd.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/fs.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/linux/linux-core.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/netbsd.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/openbsd.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/sunos.c | 6 | ||||
-rw-r--r-- | deps/uv/test/benchmark-sizes.c | 1 |
10 files changed, 122 insertions, 94 deletions
diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index cdde9059479..7c2c03f9286 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -1093,8 +1093,7 @@ UV_EXTERN int uv_async_send(uv_async_t* async); /* * uv_timer_t is a subclass of uv_handle_t. * - * Wraps libev's ev_timer watcher. Used to get woken up at a specified time - * in the future. + * Used to get woken up at a specified time in the future. */ struct uv_timer_s { UV_HANDLE_FIELDS @@ -1103,8 +1102,22 @@ struct uv_timer_s { UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* timer); -UV_EXTERN int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, - int64_t timeout, int64_t repeat); +/* + * Start the timer. `timeout` and `repeat` are in milliseconds. + * + * If timeout is zero, the callback fires on the next tick of the event loop. + * + * If repeat is non-zero, the callback fires first after timeout milliseconds + * and then repeatedly after repeat milliseconds. + * + * timeout and repeat are signed integers but that will change in a future + * version of libuv. Don't pass in negative values, you'll get a nasty surprise + * when that change becomes effective. + */ +UV_EXTERN int uv_timer_start(uv_timer_t* timer, + uv_timer_cb cb, + int64_t timeout, + int64_t repeat); UV_EXTERN int uv_timer_stop(uv_timer_t* timer); @@ -1116,10 +1129,10 @@ UV_EXTERN int uv_timer_stop(uv_timer_t* timer); UV_EXTERN int uv_timer_again(uv_timer_t* timer); /* - * Set the repeat value. Note that if the repeat value is set from a timer - * callback it does not immediately take effect. If the timer was non-repeating - * before, it will have been stopped. If it was repeating, then the old repeat - * value will have been used to schedule the next timeout. + * Set the repeat value in milliseconds. Note that if the repeat value is set + * from a timer callback it does not immediately take effect. If the timer was + * non-repeating before, it will have been stopped. If it was repeating, then + * the old repeat value will have been used to schedule the next timeout. */ UV_EXTERN void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat); @@ -1518,14 +1531,17 @@ struct uv_fs_event_s { struct uv_fs_poll_s { UV_HANDLE_FIELDS /* Private, don't touch. */ - int busy_polling; /* TODO(bnoordhuis) Fold into flags field. */ - unsigned int interval; - uint64_t start_time; - char* path; - uv_fs_poll_cb poll_cb; - uv_timer_t timer_handle; - uv_fs_t* fs_req; - uv_statbuf_t statbuf; + void* poll_ctx; + /* v0.8 ABI compatibility */ + char padding[sizeof(int) + + sizeof(unsigned int) + + sizeof(uint64_t) + + sizeof(char*) + + sizeof(uv_fs_poll_cb) + + sizeof(uv_timer_t) + + sizeof(uv_fs_t*) + + sizeof(uv_statbuf_t) + - sizeof(void*)]; }; UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle); diff --git a/deps/uv/src/fs-poll.c b/deps/uv/src/fs-poll.c index 99d3bcfae91..71eaebc0a1a 100644 --- a/deps/uv/src/fs-poll.c +++ b/deps/uv/src/fs-poll.c @@ -26,24 +26,30 @@ #include <stdlib.h> #include <string.h> +struct poll_ctx { + uv_fs_poll_t* parent_handle; /* NULL if parent has been stopped or closed */ + int busy_polling; + unsigned int interval; + uint64_t start_time; + uv_loop_t* loop; + uv_fs_poll_cb poll_cb; + uv_timer_t timer_handle; + uv_fs_t fs_req; /* TODO(bnoordhuis) mark fs_req internal */ + uv_statbuf_t statbuf; + char path[1]; /* variable length */ +}; + static int statbuf_eq(const uv_statbuf_t* a, const uv_statbuf_t* b); -static void timer_cb(uv_timer_t* timer, int status); static void poll_cb(uv_fs_t* req); +static void timer_cb(uv_timer_t* timer, int status); +static void timer_close_cb(uv_handle_t* handle); static uv_statbuf_t zero_statbuf; int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle) { - /* TODO(bnoordhuis) Mark fs_req internal. */ uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_POLL); loop->counters.fs_poll_init++; - - if (uv_timer_init(loop, &handle->timer_handle)) - return -1; - - handle->timer_handle.flags |= UV__HANDLE_INTERNAL; - uv__handle_unref(&handle->timer_handle); - return 0; } @@ -52,30 +58,37 @@ int uv_fs_poll_start(uv_fs_poll_t* handle, uv_fs_poll_cb cb, const char* path, unsigned int interval) { - uv_fs_t* req; + struct poll_ctx* ctx; + uv_loop_t* loop; size_t len; if (uv__is_active(handle)) return 0; - len = strlen(path) + 1; - req = malloc(sizeof(*req) + len); + loop = handle->loop; + len = strlen(path); + ctx = calloc(1, sizeof(*ctx) + len); + + if (ctx == NULL) + return uv__set_artificial_error(loop, UV_ENOMEM); - if (req == NULL) - return uv__set_artificial_error(handle->loop, UV_ENOMEM); + ctx->loop = loop; + ctx->poll_cb = cb; + ctx->interval = interval ? interval : 1; + ctx->start_time = uv_now(loop); + ctx->parent_handle = handle; + memcpy(ctx->path, path, len + 1); - req->data = handle; - handle->path = memcpy(req + 1, path, len); - handle->fs_req = req; - handle->poll_cb = cb; - handle->interval = interval ? interval : 1; - handle->start_time = uv_now(handle->loop); - handle->busy_polling = 0; - memset(&handle->statbuf, 0, sizeof(handle->statbuf)); + if (uv_timer_init(loop, &ctx->timer_handle)) + abort(); + + ctx->timer_handle.flags |= UV__HANDLE_INTERNAL; + uv__handle_unref(&ctx->timer_handle); - if (uv_fs_stat(handle->loop, handle->fs_req, handle->path, poll_cb)) + if (uv_fs_stat(loop, &ctx->fs_req, ctx->path, poll_cb)) abort(); + handle->poll_ctx = ctx; uv__handle_start(handle); return 0; @@ -83,25 +96,19 @@ int uv_fs_poll_start(uv_fs_poll_t* handle, int uv_fs_poll_stop(uv_fs_poll_t* handle) { + struct poll_ctx* ctx; + if (!uv__is_active(handle)) return 0; - /* Don't free the fs req if it's active. Signal poll_cb that it needs to free - * the req by removing the handle backlink. - * - * TODO(bnoordhuis) Have uv-unix postpone the close callback until the req - * finishes so we don't need this pointer / lifecycle hackery. The callback - * always runs on the next tick now. - */ - if (handle->fs_req->data) - handle->fs_req->data = NULL; - else - free(handle->fs_req); + ctx = handle->poll_ctx; + assert(ctx != NULL); + assert(ctx->parent_handle != NULL); - handle->fs_req = NULL; - handle->path = NULL; + ctx->parent_handle = NULL; + uv_timer_stop(&ctx->timer_handle); - uv_timer_stop(&handle->timer_handle); + handle->poll_ctx = NULL; uv__handle_stop(handle); return 0; @@ -110,73 +117,75 @@ int uv_fs_poll_stop(uv_fs_poll_t* handle) { void uv__fs_poll_close(uv_fs_poll_t* handle) { uv_fs_poll_stop(handle); - uv_close((uv_handle_t*)&handle->timer_handle, NULL); } static void timer_cb(uv_timer_t* timer, int status) { - uv_fs_poll_t* handle; + struct poll_ctx* ctx; - handle = container_of(timer, uv_fs_poll_t, timer_handle); - handle->start_time = uv_now(handle->loop); - handle->fs_req->data = handle; + ctx = container_of(timer, struct poll_ctx, timer_handle); - if (uv_fs_stat(handle->loop, handle->fs_req, handle->path, poll_cb)) - abort(); + if (ctx->parent_handle == NULL) { /* handle has been stopped or closed */ + uv_close((uv_handle_t*)&ctx->timer_handle, timer_close_cb); + return; + } - assert(uv__is_active(handle)); + assert(ctx->parent_handle->poll_ctx == ctx); + ctx->start_time = uv_now(ctx->loop); + + if (uv_fs_stat(ctx->loop, &ctx->fs_req, ctx->path, poll_cb)) + abort(); } static void poll_cb(uv_fs_t* req) { uv_statbuf_t* statbuf; - uv_fs_poll_t* handle; + struct poll_ctx* ctx; uint64_t interval; - handle = req->data; - - if (handle == NULL) /* Handle has been stopped or closed. */ - goto out; + ctx = container_of(req, struct poll_ctx, fs_req); - assert(req == handle->fs_req); + if (ctx->parent_handle == NULL) { /* handle has been stopped or closed */ + uv_close((uv_handle_t*)&ctx->timer_handle, timer_close_cb); + uv_fs_req_cleanup(req); + return; + } if (req->result != 0) { - if (handle->busy_polling != -req->errorno) { - uv__set_artificial_error(handle->loop, req->errorno); - handle->poll_cb(handle, -1, &handle->statbuf, &zero_statbuf); - handle->busy_polling = -req->errorno; + if (ctx->busy_polling != -req->errorno) { + uv__set_artificial_error(ctx->loop, req->errorno); + ctx->poll_cb(ctx->parent_handle, -1, &ctx->statbuf, &zero_statbuf); + ctx->busy_polling = -req->errorno; } goto out; } statbuf = req->ptr; - if (handle->busy_polling != 0) - if (handle->busy_polling < 0 || !statbuf_eq(&handle->statbuf, statbuf)) - handle->poll_cb(handle, 0, &handle->statbuf, statbuf); + if (ctx->busy_polling != 0) + if (ctx->busy_polling < 0 || !statbuf_eq(&ctx->statbuf, statbuf)) + ctx->poll_cb(ctx->parent_handle, 0, &ctx->statbuf, statbuf); - handle->statbuf = *statbuf; - handle->busy_polling = 1; + ctx->statbuf = *statbuf; + ctx->busy_polling = 1; out: uv_fs_req_cleanup(req); - if (req->data == NULL) { /* Handle has been stopped or closed. */ - free(req); - return; - } - - req->data = NULL; /* Tell uv_fs_poll_stop() it's safe to free the req. */ - /* Reschedule timer, subtract the delay from doing the stat(). */ - interval = handle->interval; - interval -= (uv_now(handle->loop) - handle->start_time) % interval; + interval = ctx->interval; + interval -= (uv_now(ctx->loop) - ctx->start_time) % interval; - if (uv_timer_start(&handle->timer_handle, timer_cb, interval, 0)) + if (uv_timer_start(&ctx->timer_handle, timer_cb, interval, 0)) abort(); } +static void timer_close_cb(uv_handle_t* handle) { + free(container_of(handle, struct poll_ctx, timer_handle)); +} + + static int statbuf_eq(const uv_statbuf_t* a, const uv_statbuf_t* b) { #ifdef _WIN32 return a->st_mtime == b->st_mtime diff --git a/deps/uv/src/unix/cygwin.c b/deps/uv/src/unix/cygwin.c index a99779d4e4c..183beb32217 100644 --- a/deps/uv/src/unix/cygwin.c +++ b/deps/uv/src/unix/cygwin.c @@ -35,7 +35,7 @@ uint64_t uv_hrtime() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } void uv_loadavg(double avg[3]) { diff --git a/deps/uv/src/unix/freebsd.c b/deps/uv/src/unix/freebsd.c index be8006c5a8c..0528835f965 100644 --- a/deps/uv/src/unix/freebsd.c +++ b/deps/uv/src/unix/freebsd.c @@ -57,7 +57,7 @@ static char *process_title; uint64_t uv_hrtime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c index e62832db5a5..c43c19f23e6 100644 --- a/deps/uv/src/unix/fs.c +++ b/deps/uv/src/unix/fs.c @@ -85,7 +85,7 @@ void uv_fs_req_cleanup(uv_fs_t* req) { if (req->cb) uv__req_unregister(req->loop, req); - free(req->path); + free((void*)req->path); req->path = NULL; switch (req->fs_type) { diff --git a/deps/uv/src/unix/linux/linux-core.c b/deps/uv/src/unix/linux/linux-core.c index 34f48a94b9f..c77c81cc920 100644 --- a/deps/uv/src/unix/linux/linux-core.c +++ b/deps/uv/src/unix/linux/linux-core.c @@ -71,7 +71,7 @@ static struct { uint64_t uv_hrtime() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } diff --git a/deps/uv/src/unix/netbsd.c b/deps/uv/src/unix/netbsd.c index a1a7091bbb0..5f7a8484991 100644 --- a/deps/uv/src/unix/netbsd.c +++ b/deps/uv/src/unix/netbsd.c @@ -38,7 +38,7 @@ uint64_t uv_hrtime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } void uv_loadavg(double avg[3]) { diff --git a/deps/uv/src/unix/openbsd.c b/deps/uv/src/unix/openbsd.c index 865f8e9e6af..a18674fabeb 100644 --- a/deps/uv/src/unix/openbsd.c +++ b/deps/uv/src/unix/openbsd.c @@ -46,7 +46,7 @@ static char *process_title; uint64_t uv_hrtime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } diff --git a/deps/uv/src/unix/sunos.c b/deps/uv/src/unix/sunos.c index 6598ea2581e..b49e4483118 100644 --- a/deps/uv/src/unix/sunos.c +++ b/deps/uv/src/unix/sunos.c @@ -346,8 +346,10 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { cpu_info->model = NULL; } else { knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"clock_MHz"); - assert(knp->data_type == KSTAT_DATA_INT32); - cpu_info->speed = knp->value.i32; + assert(knp->data_type == KSTAT_DATA_INT32 || + knp->data_type == KSTAT_DATA_INT64); + cpu_info->speed = (knp->data_type == KSTAT_DATA_INT32) ? knp->value.i32 + : knp->value.i64; knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"brand"); assert(knp->data_type == KSTAT_DATA_STRING); diff --git a/deps/uv/test/benchmark-sizes.c b/deps/uv/test/benchmark-sizes.c index b9cf74f2fbf..8ccf10ee475 100644 --- a/deps/uv/test/benchmark-sizes.c +++ b/deps/uv/test/benchmark-sizes.c @@ -36,6 +36,7 @@ BENCHMARK_IMPL(sizes) { 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_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t)); + LOGF("uv_fs_poll_t: %u bytes\n", (unsigned int) sizeof(uv_fs_poll_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_poll_t: %u bytes\n", (unsigned int) sizeof(uv_poll_t)); |