diff --git a/src/win/internal.h b/src/win/internal.h index d7aae53e..c1189e67 100644 --- a/src/win/internal.h +++ b/src/win/internal.h @@ -65,7 +65,6 @@ extern UV_THREAD_LOCAL int uv__crt_assert_enabled; /* Used by all handles. */ #define UV_HANDLE_CLOSED 0x00000002 #define UV_HANDLE_ENDGAME_QUEUED 0x00000004 -#define UV_HANDLE_ACTIVE 0x00000010 /* uv-common.h: #define UV__HANDLE_CLOSING 0x00000001 */ /* uv-common.h: #define UV__HANDLE_ACTIVE 0x00000040 */ diff --git a/src/win/loop-watcher.c b/src/win/loop-watcher.c index eb49f7cb..20e4509f 100644 --- a/src/win/loop-watcher.c +++ b/src/win/loop-watcher.c @@ -49,7 +49,7 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) { \ assert(handle->type == UV_##NAME); \ \ - if (handle->flags & UV_HANDLE_ACTIVE) \ + if (uv__is_active(handle)) \ return 0; \ \ if (cb == NULL) \ @@ -67,7 +67,6 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) { loop->name##_handles = handle; \ \ handle->name##_cb = cb; \ - handle->flags |= UV_HANDLE_ACTIVE; \ uv__handle_start(handle); \ \ return 0; \ @@ -79,7 +78,7 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) { \ assert(handle->type == UV_##NAME); \ \ - if (!(handle->flags & UV_HANDLE_ACTIVE)) \ + if (!uv__is_active(handle)) \ return 0; \ \ /* Update loop head if needed */ \ @@ -99,7 +98,6 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) { handle->name##_next->name##_prev = handle->name##_prev; \ } \ \ - handle->flags &= ~UV_HANDLE_ACTIVE; \ uv__handle_stop(handle); \ \ return 0; \ diff --git a/src/win/timer.c b/src/win/timer.c index dcd2d478..2604336c 100644 --- a/src/win/timer.c +++ b/src/win/timer.c @@ -122,14 +122,12 @@ int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, uint64_t timeout, if (timer_cb == NULL) return UV_EINVAL; - if (handle->flags & UV_HANDLE_ACTIVE) { - RB_REMOVE(uv_timer_tree_s, &loop->timers, handle); - } + if (uv__is_active(handle)) + uv_timer_stop(handle); handle->timer_cb = timer_cb; handle->due = get_clamped_due_time(loop->time, timeout); handle->repeat = repeat; - handle->flags |= UV_HANDLE_ACTIVE; uv__handle_start(handle); /* start_id is the second index to be compared in uv__timer_cmp() */ @@ -145,12 +143,10 @@ int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, uint64_t timeout, int uv_timer_stop(uv_timer_t* handle) { uv_loop_t* loop = handle->loop; - if (!(handle->flags & UV_HANDLE_ACTIVE)) + if (!uv__is_active(handle)) return 0; RB_REMOVE(uv_timer_tree_s, &loop->timers, handle); - - handle->flags &= ~UV_HANDLE_ACTIVE; uv__handle_stop(handle); return 0; @@ -225,23 +221,9 @@ void uv_process_timers(uv_loop_t* loop) { for (timer = RB_MIN(uv_timer_tree_s, &loop->timers); timer != NULL && timer->due <= loop->time; timer = RB_MIN(uv_timer_tree_s, &loop->timers)) { - RB_REMOVE(uv_timer_tree_s, &loop->timers, timer); - - if (timer->repeat != 0) { - /* If it is a repeating timer, reschedule with repeat timeout. */ - timer->due = get_clamped_due_time(timer->due, timer->repeat); - if (timer->due < loop->time) { - timer->due = loop->time; - } - if (RB_INSERT(uv_timer_tree_s, &loop->timers, timer) != NULL) { - uv_fatal_error(ERROR_INVALID_DATA, "RB_INSERT"); - } - } else { - /* If non-repeating, mark the timer as inactive. */ - timer->flags &= ~UV_HANDLE_ACTIVE; - uv__handle_stop(timer); - } + uv_timer_stop(timer); + uv_timer_again(timer); timer->timer_cb((uv_timer_t*) timer); } }