diff --git a/include/uv.h b/include/uv.h index cca152b2..2991ada8 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1107,8 +1107,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 @@ -1117,8 +1116,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); @@ -1130,10 +1143,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); diff --git a/src/unix/cygwin.c b/src/unix/cygwin.c index dbb2d8d1..8c0797e4 100644 --- a/src/unix/cygwin.c +++ b/src/unix/cygwin.c @@ -44,7 +44,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) { 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/src/unix/freebsd.c b/src/unix/freebsd.c index cff88896..76f2793a 100644 --- a/src/unix/freebsd.c +++ b/src/unix/freebsd.c @@ -66,7 +66,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) { 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/src/unix/linux/linux-core.c b/src/unix/linux/linux-core.c index 1ca92ac0..f20edd08 100644 --- a/src/unix/linux/linux-core.c +++ b/src/unix/linux/linux-core.c @@ -87,7 +87,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) { 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/src/unix/netbsd.c b/src/unix/netbsd.c index 30c458f3..b1c437bf 100644 --- a/src/unix/netbsd.c +++ b/src/unix/netbsd.c @@ -47,7 +47,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) { 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/src/unix/openbsd.c b/src/unix/openbsd.c index b3ee2297..43192709 100644 --- a/src/unix/openbsd.c +++ b/src/unix/openbsd.c @@ -55,7 +55,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) { 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/src/unix/sunos.c b/src/unix/sunos.c index 8dfc2e1c..18412b8d 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -354,8 +354,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);