|
@ -66,7 +66,6 @@ static void uv__finish_close(uv_handle_t* handle); |
|
|
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { |
|
|
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { |
|
|
uv_udp_t* udp; |
|
|
uv_udp_t* udp; |
|
|
uv_async_t* async; |
|
|
uv_async_t* async; |
|
|
uv_timer_t* timer; |
|
|
|
|
|
uv_stream_t* stream; |
|
|
uv_stream_t* stream; |
|
|
uv_process_t* process; |
|
|
uv_process_t* process; |
|
|
|
|
|
|
|
@ -123,11 +122,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case UV_TIMER: |
|
|
case UV_TIMER: |
|
|
timer = (uv_timer_t*)handle; |
|
|
uv_timer_stop((uv_timer_t*)handle); |
|
|
if (ev_is_active(&timer->timer_watcher)) { |
|
|
|
|
|
ev_ref(timer->loop->ev); |
|
|
|
|
|
} |
|
|
|
|
|
ev_timer_stop(timer->loop->ev, &timer->timer_watcher); |
|
|
|
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case UV_PROCESS: |
|
|
case UV_PROCESS: |
|
@ -524,10 +519,23 @@ int uv_async_send(uv_async_t* async) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int uv__timer_active(const uv_timer_t* timer) { |
|
|
|
|
|
return timer->flags & UV_TIMER_ACTIVE; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int uv__timer_repeating(const uv_timer_t* timer) { |
|
|
|
|
|
return timer->flags & UV_TIMER_REPEAT; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { |
|
|
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { |
|
|
uv_timer_t* timer = w->data; |
|
|
uv_timer_t* timer = w->data; |
|
|
|
|
|
|
|
|
if (!ev_is_active(w)) { |
|
|
assert(uv__timer_active(timer)); |
|
|
|
|
|
|
|
|
|
|
|
if (!uv__timer_repeating(timer)) { |
|
|
|
|
|
timer->flags &= ~UV_TIMER_ACTIVE; |
|
|
ev_ref(EV_A); |
|
|
ev_ref(EV_A); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -550,43 +558,61 @@ int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) { |
|
|
|
|
|
|
|
|
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, |
|
|
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, |
|
|
int64_t repeat) { |
|
|
int64_t repeat) { |
|
|
if (ev_is_active(&timer->timer_watcher)) { |
|
|
if (uv__timer_active(timer)) { |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
timer->timer_cb = cb; |
|
|
timer->timer_cb = cb; |
|
|
|
|
|
timer->flags |= UV_TIMER_ACTIVE; |
|
|
|
|
|
|
|
|
|
|
|
if (repeat) |
|
|
|
|
|
timer->flags |= UV_TIMER_REPEAT; |
|
|
|
|
|
else |
|
|
|
|
|
timer->flags &= ~UV_TIMER_REPEAT; |
|
|
|
|
|
|
|
|
ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); |
|
|
ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); |
|
|
ev_timer_start(timer->loop->ev, &timer->timer_watcher); |
|
|
ev_timer_start(timer->loop->ev, &timer->timer_watcher); |
|
|
ev_unref(timer->loop->ev); |
|
|
ev_unref(timer->loop->ev); |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int uv_timer_stop(uv_timer_t* timer) { |
|
|
int uv_timer_stop(uv_timer_t* timer) { |
|
|
if (ev_is_active(&timer->timer_watcher)) { |
|
|
if (uv__timer_active(timer)) { |
|
|
ev_ref(timer->loop->ev); |
|
|
ev_ref(timer->loop->ev); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
timer->flags &= ~(UV_TIMER_ACTIVE | UV_TIMER_REPEAT); |
|
|
ev_timer_stop(timer->loop->ev, &timer->timer_watcher); |
|
|
ev_timer_stop(timer->loop->ev, &timer->timer_watcher); |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int uv_timer_again(uv_timer_t* timer) { |
|
|
int uv_timer_again(uv_timer_t* timer) { |
|
|
if (!ev_is_active(&timer->timer_watcher)) { |
|
|
if (!uv__timer_active(timer)) { |
|
|
uv__set_sys_error(timer->loop, EINVAL); |
|
|
uv__set_sys_error(timer->loop, EINVAL); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert(uv__timer_repeating(timer)); |
|
|
ev_timer_again(timer->loop->ev, &timer->timer_watcher); |
|
|
ev_timer_again(timer->loop->ev, &timer->timer_watcher); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat) { |
|
|
void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat) { |
|
|
assert(timer->type == UV_TIMER); |
|
|
assert(timer->type == UV_TIMER); |
|
|
timer->timer_watcher.repeat = repeat / 1000.0; |
|
|
timer->timer_watcher.repeat = repeat / 1000.0; |
|
|
|
|
|
|
|
|
|
|
|
if (repeat) |
|
|
|
|
|
timer->flags |= UV_TIMER_REPEAT; |
|
|
|
|
|
else |
|
|
|
|
|
timer->flags &= ~UV_TIMER_REPEAT; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64_t uv_timer_get_repeat(uv_timer_t* timer) { |
|
|
int64_t uv_timer_get_repeat(uv_timer_t* timer) { |
|
|
assert(timer->type == UV_TIMER); |
|
|
assert(timer->type == UV_TIMER); |
|
|
return (int64_t)(1000 * timer->timer_watcher.repeat); |
|
|
return (int64_t)(1000 * timer->timer_watcher.repeat); |
|
|