Skip to content

Commit 3aa2fd3

Browse files
committed
uv: upgrade to b3fe183
1 parent a63ce6e commit 3aa2fd3

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

deps/uv/src/unix/core.c

+36-10
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ static void uv__finish_close(uv_handle_t* handle);
6666
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
6767
uv_udp_t* udp;
6868
uv_async_t* async;
69-
uv_timer_t* timer;
7069
uv_stream_t* stream;
7170
uv_process_t* process;
7271

@@ -123,11 +122,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
123122
break;
124123

125124
case UV_TIMER:
126-
timer = (uv_timer_t*)handle;
127-
if (ev_is_active(&timer->timer_watcher)) {
128-
ev_ref(timer->loop->ev);
129-
}
130-
ev_timer_stop(timer->loop->ev, &timer->timer_watcher);
125+
uv_timer_stop((uv_timer_t*)handle);
131126
break;
132127

133128
case UV_PROCESS:
@@ -524,10 +519,23 @@ int uv_async_send(uv_async_t* async) {
524519
}
525520

526521

522+
static int uv__timer_active(const uv_timer_t* timer) {
523+
return timer->flags & UV_TIMER_ACTIVE;
524+
}
525+
526+
527+
static int uv__timer_repeating(const uv_timer_t* timer) {
528+
return timer->flags & UV_TIMER_REPEAT;
529+
}
530+
531+
527532
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) {
528533
uv_timer_t* timer = w->data;
529534

530-
if (!ev_is_active(w)) {
535+
assert(uv__timer_active(timer));
536+
537+
if (!uv__timer_repeating(timer)) {
538+
timer->flags &= ~UV_TIMER_ACTIVE;
531539
ev_ref(EV_A);
532540
}
533541

@@ -550,43 +558,61 @@ int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) {
550558

551559
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout,
552560
int64_t repeat) {
553-
if (ev_is_active(&timer->timer_watcher)) {
561+
if (uv__timer_active(timer)) {
554562
return -1;
555563
}
556564

557565
timer->timer_cb = cb;
566+
timer->flags |= UV_TIMER_ACTIVE;
567+
568+
if (repeat)
569+
timer->flags |= UV_TIMER_REPEAT;
570+
else
571+
timer->flags &= ~UV_TIMER_REPEAT;
572+
558573
ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0);
559574
ev_timer_start(timer->loop->ev, &timer->timer_watcher);
560575
ev_unref(timer->loop->ev);
576+
561577
return 0;
562578
}
563579

564580

565581
int uv_timer_stop(uv_timer_t* timer) {
566-
if (ev_is_active(&timer->timer_watcher)) {
582+
if (uv__timer_active(timer)) {
567583
ev_ref(timer->loop->ev);
568584
}
569585

586+
timer->flags &= ~(UV_TIMER_ACTIVE | UV_TIMER_REPEAT);
570587
ev_timer_stop(timer->loop->ev, &timer->timer_watcher);
588+
571589
return 0;
572590
}
573591

574592

575593
int uv_timer_again(uv_timer_t* timer) {
576-
if (!ev_is_active(&timer->timer_watcher)) {
594+
if (!uv__timer_active(timer)) {
577595
uv__set_sys_error(timer->loop, EINVAL);
578596
return -1;
579597
}
580598

599+
assert(uv__timer_repeating(timer));
581600
ev_timer_again(timer->loop->ev, &timer->timer_watcher);
582601
return 0;
583602
}
584603

604+
585605
void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat) {
586606
assert(timer->type == UV_TIMER);
587607
timer->timer_watcher.repeat = repeat / 1000.0;
608+
609+
if (repeat)
610+
timer->flags |= UV_TIMER_REPEAT;
611+
else
612+
timer->flags &= ~UV_TIMER_REPEAT;
588613
}
589614

615+
590616
int64_t uv_timer_get_repeat(uv_timer_t* timer) {
591617
assert(timer->type == UV_TIMER);
592618
return (int64_t)(1000 * timer->timer_watcher.repeat);

deps/uv/src/unix/ev/ev.c

+1
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,7 @@ void
25542554
ev_unref (EV_P)
25552555
{
25562556
--activecnt;
2557+
if (activecnt < 0) abort();
25572558
}
25582559

25592560
void

deps/uv/src/unix/internal.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ enum {
151151
UV_READABLE = 0x20, /* The stream is readable */
152152
UV_WRITABLE = 0x40, /* The stream is writable */
153153
UV_TCP_NODELAY = 0x080, /* Disable Nagle. */
154-
UV_TCP_KEEPALIVE = 0x100 /* Turn on keep-alive. */
154+
UV_TCP_KEEPALIVE = 0x100, /* Turn on keep-alive. */
155+
UV_TIMER_ACTIVE = 0x080,
156+
UV_TIMER_REPEAT = 0x100
155157
};
156158

157159
size_t uv__strlcpy(char* dst, const char* src, size_t size);

deps/uv/src/unix/kqueue.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ static void uv__fs_event(EV_P_ ev_io* w, int revents) {
6868

6969
handle->cb(handle, NULL, events, 0);
7070

71-
uv__fs_event_stop(handle);
71+
if (handle->fd == -1)
72+
return;
7273

7374
/* File watcher operates in one-shot mode, re-arm it. */
74-
if (handle->fd != -1)
75-
uv__fs_event_start(handle);
75+
uv__fs_event_stop(handle);
76+
uv__fs_event_start(handle);
7677
}
7778

7879

0 commit comments

Comments
 (0)