Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af7960b

Browse files
committed
uv: upgrade to 2f886c8
1 parent 18acdff commit af7960b

File tree

23 files changed

+568
-301
lines changed

23 files changed

+568
-301
lines changed

deps/uv/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ UpgradeLog*.XML
2929
Debug
3030
Release
3131
ipch
32+
*.mk
33+
*.Makefile

deps/uv/config-unix.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ EIO_CONFIG=config_linux.h
6363
CSTDFLAG += -D_GNU_SOURCE
6464
CPPFLAGS += -Isrc/ares/config_linux
6565
LINKFLAGS+=-lrt
66-
OBJS += src/unix/linux.o
66+
OBJS += src/unix/linux/core.o src/unix/linux/inotify.o
6767
endif
6868

6969
ifeq (FreeBSD,$(uname_S))

deps/uv/include/uv-private/uv-unix.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ typedef pthread_rwlock_t uv_rwlock_t;
5555
typedef void* uv_lib_t;
5656
#define UV_DYNAMIC /* empty */
5757

58+
#if __linux__
59+
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS \
60+
/* RB_HEAD(uv__inotify_watchers, uv_fs_event_s) */ \
61+
struct uv__inotify_watchers { \
62+
struct uv_fs_event_s* rbh_root; \
63+
} inotify_watchers; \
64+
ev_io inotify_read_watcher; \
65+
int inotify_fd;
66+
#else
67+
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS
68+
#endif
69+
5870
#define UV_LOOP_PRIVATE_FIELDS \
5971
ares_channel channel; \
6072
/* \
@@ -65,7 +77,8 @@ typedef void* uv_lib_t;
6577
ev_timer timer; \
6678
/* Poll result queue */ \
6779
eio_channel uv_eio_channel; \
68-
struct ev_loop* ev;
80+
struct ev_loop* ev; \
81+
UV_LOOP_PRIVATE_PLATFORM_FIELDS
6982

7083
#define UV_REQ_BUFSML_SIZE (4)
7184

@@ -195,9 +208,16 @@ typedef void* uv_lib_t;
195208
/* UV_FS_EVENT_PRIVATE_FIELDS */
196209
#if defined(__linux__)
197210

198-
#define UV_FS_EVENT_PRIVATE_FIELDS \
199-
ev_io read_watcher; \
200-
uv_fs_event_cb cb; \
211+
#define UV_FS_EVENT_PRIVATE_FIELDS \
212+
/* RB_ENTRY(fs_event_s) node; */ \
213+
struct { \
214+
struct uv_fs_event_s* rbe_left; \
215+
struct uv_fs_event_s* rbe_right; \
216+
struct uv_fs_event_s* rbe_parent; \
217+
int rbe_color; \
218+
} node; \
219+
ev_io read_watcher; \
220+
uv_fs_event_cb cb;
201221

202222
#elif (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) \
203223
|| defined(__FreeBSD__) \

deps/uv/include/uv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,8 @@ struct uv_loop_s {
15041504
#undef UV_FS_REQ_PRIVATE_FIELDS
15051505
#undef UV_WORK_PRIVATE_FIELDS
15061506
#undef UV_FS_EVENT_PRIVATE_FIELDS
1507+
#undef UV_LOOP_PRIVATE_FIELDS
1508+
#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
15071509

15081510
#ifdef __cplusplus
15091511
}

deps/uv/src/unix/core.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ static void uv__finish_close(uv_handle_t* handle);
6565

6666
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
6767
uv_async_t* async;
68-
uv_timer_t* timer;
6968
uv_stream_t* stream;
7069
uv_process_t* process;
7170

@@ -118,11 +117,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
118117
break;
119118

120119
case UV_TIMER:
121-
timer = (uv_timer_t*)handle;
122-
if (ev_is_active(&timer->timer_watcher)) {
123-
ev_ref(timer->loop->ev);
124-
}
125-
ev_timer_stop(timer->loop->ev, &timer->timer_watcher);
120+
uv_timer_stop((uv_timer_t*)handle);
126121
break;
127122

128123
case UV_PROCESS:
@@ -157,6 +152,7 @@ static int uv__loop_init(uv_loop_t* loop,
157152
#endif
158153
ev_set_userdata(loop->ev, loop);
159154
eio_channel_init(&loop->uv_eio_channel, loop);
155+
uv__loop_platform_init(loop);
160156
return 0;
161157
}
162158

@@ -179,11 +175,10 @@ uv_loop_t* uv_loop_new(void) {
179175
void uv_loop_delete(uv_loop_t* loop) {
180176
uv_ares_destroy(loop, loop->channel);
181177
ev_loop_destroy(loop->ev);
182-
178+
uv__loop_platform_delete(loop);
183179
#ifndef NDEBUG
184-
memset(loop, 0, sizeof *loop);
180+
memset(loop, -1, sizeof *loop);
185181
#endif
186-
187182
if (loop == default_loop_ptr)
188183
default_loop_ptr = NULL;
189184
else
@@ -531,10 +526,23 @@ int uv_async_send(uv_async_t* async) {
531526
}
532527

533528

529+
static int uv__timer_active(const uv_timer_t* timer) {
530+
return timer->flags & UV_TIMER_ACTIVE;
531+
}
532+
533+
534+
static int uv__timer_repeating(const uv_timer_t* timer) {
535+
return timer->flags & UV_TIMER_REPEAT;
536+
}
537+
538+
534539
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) {
535540
uv_timer_t* timer = container_of(w, uv_timer_t, timer_watcher);
536541

537-
if (!ev_is_active(w)) {
542+
assert(uv__timer_active(timer));
543+
544+
if (!uv__timer_repeating(timer)) {
545+
timer->flags &= ~UV_TIMER_ACTIVE;
538546
ev_ref(EV_A);
539547
}
540548

@@ -556,43 +564,61 @@ int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) {
556564

557565
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout,
558566
int64_t repeat) {
559-
if (ev_is_active(&timer->timer_watcher)) {
567+
if (uv__timer_active(timer)) {
560568
return -1;
561569
}
562570

563571
timer->timer_cb = cb;
572+
timer->flags |= UV_TIMER_ACTIVE;
573+
574+
if (repeat)
575+
timer->flags |= UV_TIMER_REPEAT;
576+
else
577+
timer->flags &= ~UV_TIMER_REPEAT;
578+
564579
ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0);
565580
ev_timer_start(timer->loop->ev, &timer->timer_watcher);
566581
ev_unref(timer->loop->ev);
582+
567583
return 0;
568584
}
569585

570586

571587
int uv_timer_stop(uv_timer_t* timer) {
572-
if (ev_is_active(&timer->timer_watcher)) {
588+
if (uv__timer_active(timer)) {
573589
ev_ref(timer->loop->ev);
574590
}
575591

592+
timer->flags &= ~(UV_TIMER_ACTIVE | UV_TIMER_REPEAT);
576593
ev_timer_stop(timer->loop->ev, &timer->timer_watcher);
594+
577595
return 0;
578596
}
579597

580598

581599
int uv_timer_again(uv_timer_t* timer) {
582-
if (!ev_is_active(&timer->timer_watcher)) {
600+
if (!uv__timer_active(timer)) {
583601
uv__set_sys_error(timer->loop, EINVAL);
584602
return -1;
585603
}
586604

605+
assert(uv__timer_repeating(timer));
587606
ev_timer_again(timer->loop->ev, &timer->timer_watcher);
588607
return 0;
589608
}
590609

610+
591611
void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat) {
592612
assert(timer->type == UV_TIMER);
593613
timer->timer_watcher.repeat = repeat / 1000.0;
614+
615+
if (repeat)
616+
timer->flags |= UV_TIMER_REPEAT;
617+
else
618+
timer->flags &= ~UV_TIMER_REPEAT;
594619
}
595620

621+
596622
int64_t uv_timer_get_repeat(uv_timer_t* timer) {
597623
assert(timer->type == UV_TIMER);
598624
return (int64_t)(1000 * timer->timer_watcher.repeat);

deps/uv/src/unix/darwin.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ uint64_t uv_hrtime() {
7373
int uv_exepath(char* buffer, size_t* size) {
7474
uint32_t usize;
7575
int result;
76-
char* path;
7776
char* fullpath;
7877

7978
if (!buffer || !size) {
@@ -84,11 +83,9 @@ int uv_exepath(char* buffer, size_t* size) {
8483
result = _NSGetExecutablePath(buffer, &usize);
8584
if (result) return result;
8685

87-
path = (char*)malloc(2 * PATH_MAX);
88-
fullpath = realpath(buffer, path);
86+
fullpath = realpath(buffer, NULL);
8987

9088
if (fullpath == NULL) {
91-
free(path);
9289
return -1;
9390
}
9491

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

Lines changed: 1 addition & 0 deletions
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/freebsd.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
#undef NANOSEC
4141
#define NANOSEC 1000000000
4242

43+
#ifndef CPUSTATES
44+
# define CPUSTATES 5U
45+
#endif
46+
#ifndef CP_USER
47+
# define CP_USER 0
48+
# define CP_NICE 1
49+
# define CP_SYS 2
50+
# define CP_IDLE 3
51+
# define CP_INTR 4
52+
#endif
4353

4454
static char *process_title;
4555

@@ -164,7 +174,11 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
164174
kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs);
165175
if (kinfo == NULL) goto error;
166176

177+
#ifdef __DragonFly__
178+
*rss = kinfo->kp_vm_rssize * page_size;
179+
#else
167180
*rss = kinfo->ki_rssize * page_size;
181+
#endif
168182

169183
kvm_close(kd);
170184

@@ -227,10 +241,17 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
227241
}
228242
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu */
229243
size = sizeof(maxcpus);
244+
#ifdef __DragonFly__
245+
if (sysctlbyname("hw.ncpu", &maxcpus, &size, NULL, 0) < 0) {
246+
free(*cpu_infos);
247+
return uv__new_sys_error(errno);
248+
}
249+
#else
230250
if (sysctlbyname("kern.smp.maxcpus", &maxcpus, &size, NULL, 0) < 0) {
231251
free(*cpu_infos);
232252
return uv__new_sys_error(errno);
233253
}
254+
#endif
234255

235256
size = maxcpus * CPUSTATES * sizeof(long);
236257

deps/uv/src/unix/internal.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ enum {
160160
UV_READABLE = 0x20, /* The stream is readable */
161161
UV_WRITABLE = 0x40, /* The stream is writable */
162162
UV_TCP_NODELAY = 0x080, /* Disable Nagle. */
163-
UV_TCP_KEEPALIVE = 0x100 /* Turn on keep-alive. */
163+
UV_TCP_KEEPALIVE = 0x100, /* Turn on keep-alive. */
164+
UV_TIMER_ACTIVE = 0x080,
165+
UV_TIMER_REPEAT = 0x100
164166
};
165167

166168
/* core */
@@ -217,4 +219,14 @@ void uv__fs_event_destroy(uv_fs_event_t* handle);
217219
int uv__make_socketpair(int fds[2], int flags);
218220
int uv__make_pipe(int fds[2], int flags);
219221

222+
#if __linux__
223+
void uv__inotify_loop_init(uv_loop_t* loop);
224+
void uv__inotify_loop_delete(uv_loop_t* loop);
225+
# define uv__loop_platform_init(loop) uv__inotify_loop_init(loop)
226+
# define uv__loop_platform_delete(loop) uv__inotify_loop_delete(loop)
227+
#else
228+
# define uv__loop_platform_init(loop)
229+
# define uv__loop_platform_delete(loop)
230+
#endif
231+
220232
#endif /* UV_UNIX_INTERNAL_H_ */

0 commit comments

Comments
 (0)