Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
uv: upgrade to 2f886c8
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Feb 28, 2012
1 parent 18acdff commit af7960b
Show file tree
Hide file tree
Showing 23 changed files with 568 additions and 301 deletions.
2 changes: 2 additions & 0 deletions deps/uv/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ UpgradeLog*.XML
Debug
Release
ipch
*.mk
*.Makefile
2 changes: 1 addition & 1 deletion deps/uv/config-unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ EIO_CONFIG=config_linux.h
CSTDFLAG += -D_GNU_SOURCE
CPPFLAGS += -Isrc/ares/config_linux
LINKFLAGS+=-lrt
OBJS += src/unix/linux.o
OBJS += src/unix/linux/core.o src/unix/linux/inotify.o
endif

ifeq (FreeBSD,$(uname_S))
Expand Down
28 changes: 24 additions & 4 deletions deps/uv/include/uv-private/uv-unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ typedef pthread_rwlock_t uv_rwlock_t;
typedef void* uv_lib_t;
#define UV_DYNAMIC /* empty */

#if __linux__
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS \
/* RB_HEAD(uv__inotify_watchers, uv_fs_event_s) */ \
struct uv__inotify_watchers { \
struct uv_fs_event_s* rbh_root; \
} inotify_watchers; \
ev_io inotify_read_watcher; \
int inotify_fd;
#else
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS
#endif

#define UV_LOOP_PRIVATE_FIELDS \
ares_channel channel; \
/* \
Expand All @@ -65,7 +77,8 @@ typedef void* uv_lib_t;
ev_timer timer; \
/* Poll result queue */ \
eio_channel uv_eio_channel; \
struct ev_loop* ev;
struct ev_loop* ev; \
UV_LOOP_PRIVATE_PLATFORM_FIELDS

#define UV_REQ_BUFSML_SIZE (4)

Expand Down Expand Up @@ -195,9 +208,16 @@ typedef void* uv_lib_t;
/* UV_FS_EVENT_PRIVATE_FIELDS */
#if defined(__linux__)

#define UV_FS_EVENT_PRIVATE_FIELDS \
ev_io read_watcher; \
uv_fs_event_cb cb; \
#define UV_FS_EVENT_PRIVATE_FIELDS \
/* RB_ENTRY(fs_event_s) node; */ \
struct { \
struct uv_fs_event_s* rbe_left; \
struct uv_fs_event_s* rbe_right; \
struct uv_fs_event_s* rbe_parent; \
int rbe_color; \
} node; \
ev_io read_watcher; \
uv_fs_event_cb cb;

#elif (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) \
|| defined(__FreeBSD__) \
Expand Down
2 changes: 2 additions & 0 deletions deps/uv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ struct uv_loop_s {
#undef UV_FS_REQ_PRIVATE_FIELDS
#undef UV_WORK_PRIVATE_FIELDS
#undef UV_FS_EVENT_PRIVATE_FIELDS
#undef UV_LOOP_PRIVATE_FIELDS
#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS

#ifdef __cplusplus
}
Expand Down
52 changes: 39 additions & 13 deletions deps/uv/src/unix/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static void uv__finish_close(uv_handle_t* handle);

void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
uv_async_t* async;
uv_timer_t* timer;
uv_stream_t* stream;
uv_process_t* process;

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

case UV_TIMER:
timer = (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);
uv_timer_stop((uv_timer_t*)handle);
break;

case UV_PROCESS:
Expand Down Expand Up @@ -157,6 +152,7 @@ static int uv__loop_init(uv_loop_t* loop,
#endif
ev_set_userdata(loop->ev, loop);
eio_channel_init(&loop->uv_eio_channel, loop);
uv__loop_platform_init(loop);
return 0;
}

Expand All @@ -179,11 +175,10 @@ uv_loop_t* uv_loop_new(void) {
void uv_loop_delete(uv_loop_t* loop) {
uv_ares_destroy(loop, loop->channel);
ev_loop_destroy(loop->ev);

uv__loop_platform_delete(loop);
#ifndef NDEBUG
memset(loop, 0, sizeof *loop);
memset(loop, -1, sizeof *loop);
#endif

if (loop == default_loop_ptr)
default_loop_ptr = NULL;
else
Expand Down Expand Up @@ -531,10 +526,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) {
uv_timer_t* timer = container_of(w, uv_timer_t, timer_watcher);

if (!ev_is_active(w)) {
assert(uv__timer_active(timer));

if (!uv__timer_repeating(timer)) {
timer->flags &= ~UV_TIMER_ACTIVE;
ev_ref(EV_A);
}

Expand All @@ -556,43 +564,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,
int64_t repeat) {
if (ev_is_active(&timer->timer_watcher)) {
if (uv__timer_active(timer)) {
return -1;
}

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_start(timer->loop->ev, &timer->timer_watcher);
ev_unref(timer->loop->ev);

return 0;
}


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);
}

timer->flags &= ~(UV_TIMER_ACTIVE | UV_TIMER_REPEAT);
ev_timer_stop(timer->loop->ev, &timer->timer_watcher);

return 0;
}


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);
return -1;
}

assert(uv__timer_repeating(timer));
ev_timer_again(timer->loop->ev, &timer->timer_watcher);
return 0;
}


void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat) {
assert(timer->type == UV_TIMER);
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) {
assert(timer->type == UV_TIMER);
return (int64_t)(1000 * timer->timer_watcher.repeat);
Expand Down
5 changes: 1 addition & 4 deletions deps/uv/src/unix/darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ uint64_t uv_hrtime() {
int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;
int result;
char* path;
char* fullpath;

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

path = (char*)malloc(2 * PATH_MAX);
fullpath = realpath(buffer, path);
fullpath = realpath(buffer, NULL);

if (fullpath == NULL) {
free(path);
return -1;
}

Expand Down
1 change: 1 addition & 0 deletions deps/uv/src/unix/ev/ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,7 @@ void
ev_unref (EV_P)
{
--activecnt;
if (activecnt < 0) abort();
}

void
Expand Down
21 changes: 21 additions & 0 deletions deps/uv/src/unix/freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
#undef NANOSEC
#define NANOSEC 1000000000

#ifndef CPUSTATES
# define CPUSTATES 5U
#endif
#ifndef CP_USER
# define CP_USER 0
# define CP_NICE 1
# define CP_SYS 2
# define CP_IDLE 3
# define CP_INTR 4
#endif

static char *process_title;

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

#ifdef __DragonFly__
*rss = kinfo->kp_vm_rssize * page_size;
#else
*rss = kinfo->ki_rssize * page_size;
#endif

kvm_close(kd);

Expand Down Expand Up @@ -227,10 +241,17 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
}
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu */
size = sizeof(maxcpus);
#ifdef __DragonFly__
if (sysctlbyname("hw.ncpu", &maxcpus, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
#else
if (sysctlbyname("kern.smp.maxcpus", &maxcpus, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
#endif

size = maxcpus * CPUSTATES * sizeof(long);

Expand Down
14 changes: 13 additions & 1 deletion deps/uv/src/unix/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ enum {
UV_READABLE = 0x20, /* The stream is readable */
UV_WRITABLE = 0x40, /* The stream is writable */
UV_TCP_NODELAY = 0x080, /* Disable Nagle. */
UV_TCP_KEEPALIVE = 0x100 /* Turn on keep-alive. */
UV_TCP_KEEPALIVE = 0x100, /* Turn on keep-alive. */
UV_TIMER_ACTIVE = 0x080,
UV_TIMER_REPEAT = 0x100
};

/* core */
Expand Down Expand Up @@ -217,4 +219,14 @@ void uv__fs_event_destroy(uv_fs_event_t* handle);
int uv__make_socketpair(int fds[2], int flags);
int uv__make_pipe(int fds[2], int flags);

#if __linux__
void uv__inotify_loop_init(uv_loop_t* loop);
void uv__inotify_loop_delete(uv_loop_t* loop);
# define uv__loop_platform_init(loop) uv__inotify_loop_init(loop)
# define uv__loop_platform_delete(loop) uv__inotify_loop_delete(loop)
#else
# define uv__loop_platform_init(loop)
# define uv__loop_platform_delete(loop)
#endif

#endif /* UV_UNIX_INTERNAL_H_ */
Loading

0 comments on commit af7960b

Please sign in to comment.