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

Commit

Permalink
upgrade libuv to 0303197
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Oct 4, 2011
1 parent bc7cfd7 commit 627f379
Show file tree
Hide file tree
Showing 30 changed files with 776 additions and 209 deletions.
5 changes: 4 additions & 1 deletion deps/uv/config-unix.mk
Expand Up @@ -44,7 +44,7 @@ ifeq (SunOS,$(uname_S))
EV_CONFIG=config_sunos.h
EIO_CONFIG=config_sunos.h
CPPFLAGS += -Isrc/ares/config_sunos -D__EXTENSIONS__ -D_XOPEN_SOURCE=500
LINKFLAGS+=-lsocket -lnsl
LINKFLAGS+=-lsocket -lnsl -lkstat
OBJS += src/unix/sunos.o
endif

Expand All @@ -54,6 +54,7 @@ EIO_CONFIG=config_darwin.h
CPPFLAGS += -Isrc/ares/config_darwin
LINKFLAGS+=-framework CoreServices
OBJS += src/unix/darwin.o
OBJS += src/unix/kqueue.o
endif

ifeq (Linux,$(uname_S))
Expand All @@ -71,6 +72,7 @@ EIO_CONFIG=config_freebsd.h
CPPFLAGS += -Isrc/ares/config_freebsd
LINKFLAGS+=
OBJS += src/unix/freebsd.o
OBJS += src/unix/kqueue.o
endif

ifeq (NetBSD,$(uname_S))
Expand All @@ -79,6 +81,7 @@ EIO_CONFIG=config_netbsd.h
CPPFLAGS += -Isrc/ares/config_netbsd
LINKFLAGS+=
OBJS += src/unix/netbsd.o
OBJS += src/unix/kqueue.o
endif

ifneq (,$(findstring CYGWIN,$(uname_S)))
Expand Down
1 change: 1 addition & 0 deletions deps/uv/include/uv-private/ev.h
Expand Up @@ -207,6 +207,7 @@ enum {
EV_NONE = 0x00, /* no events */
EV_READ = 0x01, /* ev_io detected read will not block */
EV_WRITE = 0x02, /* ev_io detected write will not block */
EV_LIBUV_KQUEUE_HACK = 0x40,
EV__IOFDSET = 0x80, /* internal use only */
EV_IO = EV_READ, /* alias for type-detection */
EV_TIMER = 0x00000100, /* timer timed out */
Expand Down
33 changes: 24 additions & 9 deletions deps/uv/include/uv-private/uv-unix.h
Expand Up @@ -27,10 +27,6 @@
#include "ev.h"
#include "eio.h"

#if defined(__linux__)
#include "uv-private/uv-linux.h"
#endif

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
Expand All @@ -47,11 +43,6 @@ typedef struct {

typedef int uv_file;

/* Stub. Remove it once all platforms support the file watcher API. */
#ifndef UV_FS_EVENT_PRIVATE_FIELDS
#define UV_FS_EVENT_PRIVATE_FIELDS /* empty */
#endif

#define UV_LOOP_PRIVATE_FIELDS \
ares_channel channel; \
/* \
Expand Down Expand Up @@ -188,4 +179,28 @@ typedef int uv_file;
struct termios orig_termios; \
int mode;

/* UV_FS_EVENT_PRIVATE_FIELDS */
#if defined(__linux__)

#define UV_FS_EVENT_PRIVATE_FIELDS \
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__) \
|| defined(__OpenBSD__) \
|| defined(__NetBSD__)

#define UV_FS_EVENT_PRIVATE_FIELDS \
ev_io event_watcher; \
uv_fs_event_cb cb; \
int fflags; \

#else

/* Stub for platforms where the file watcher isn't implemented yet. */
#define UV_FS_EVENT_PRIVATE_FIELDS

#endif

#endif /* UV_UNIX_H */
7 changes: 7 additions & 0 deletions deps/uv/include/uv.h
Expand Up @@ -1044,6 +1044,9 @@ struct uv_fs_event_s {
};


/* Gets load avg */
void uv_loadavg(double avg[3]);

/*
* If filename is a directory then we will watch for all events in that
* directory. If filename is a file - we will only get events from that
Expand All @@ -1065,6 +1068,10 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
/* Gets the executable path */
int uv_exepath(char* buffer, size_t* size);

/* Memory info */
double uv_get_free_memory(void);
double uv_get_total_memory(void);

/*
* Returns the current high-resolution real time. This is expressed in
* nanoseconds. It is relative to an arbitrary time in the past. It is not
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/core.c
Expand Up @@ -172,7 +172,7 @@ void uv_loop_delete(uv_loop_t* loop) {
uv_loop_t* uv_default_loop() {
if (!default_loop_ptr) {
default_loop_ptr = &default_loop_struct;
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
#if HAVE_KQUEUE
default_loop_struct.ev = ev_default_loop(EVBACKEND_KQUEUE);
#else
default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO);
Expand Down
12 changes: 12 additions & 0 deletions deps/uv/src/unix/cygwin.c
Expand Up @@ -36,6 +36,11 @@ uint64_t uv_hrtime() {
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
}

void uv_loadavg(double avg[3]) {
/* Unsupported as of cygwin 1.7.7 */
avg[0] = avg[1] = avg[2] = 0;
}


int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;
Expand All @@ -53,6 +58,13 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}

double uv_get_free_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
}

double uv_get_total_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
}

int uv_fs_event_init(uv_loop_t* loop,
uv_fs_event_t* handle,
Expand Down
41 changes: 33 additions & 8 deletions deps/uv/src/unix/darwin.c
Expand Up @@ -29,6 +29,9 @@
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <unistd.h> /* sysconf */


uint64_t uv_hrtime() {
Expand Down Expand Up @@ -68,16 +71,38 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}

double uv_get_free_memory(void) {
vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);

int uv_fs_event_init(uv_loop_t* loop,
uv_fs_event_t* handle,
const char* filename,
uv_fs_event_cb cb) {
uv__set_sys_error(loop, ENOSYS);
return -1;
if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) {
return -1;
}

return (double) info.free_count * sysconf(_SC_PAGESIZE);
}

double uv_get_total_memory(void) {
uint64_t info;
int which[] = {CTL_HW, HW_MEMSIZE};
size_t size = sizeof(info);

if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
return -1;
}

return (double) info;
}

void uv_loadavg(double avg[3]) {
struct loadavg info;
size_t size = sizeof(info);
int which[] = {CTL_VM, VM_LOADAVG};

if (sysctl(which, 2, &info, &size, NULL, 0) < 0) return;

void uv__fs_event_destroy(uv_fs_event_t* handle) {
assert(0 && "implement me");
avg[0] = (double) info.ldavg[0] / info.fscale;
avg[1] = (double) info.ldavg[1] / info.fscale;
avg[2] = (double) info.ldavg[2] / info.fscale;
}
3 changes: 2 additions & 1 deletion deps/uv/src/unix/ev/ev.c
Expand Up @@ -2663,7 +2663,8 @@ ev_io_start (EV_P_ ev_io *w)
return;

assert (("libev: ev_io_start called with negative fd", fd >= 0));
assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
assert (("libev: ev_io_start called with illegal event mask",
!(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE | EV_LIBUV_KQUEUE_HACK))));

EV_FREQUENT_CHECK;

Expand Down
15 changes: 15 additions & 0 deletions deps/uv/src/unix/ev/ev_kqueue.c
Expand Up @@ -43,6 +43,9 @@
#include <string.h>
#include <errno.h>

extern void
uv__kqueue_hack (EV_P_ int fflags, ev_io *w);

void inline_speed
kqueue_change (EV_P_ int fd, int filter, int flags, int fflags)
{
Expand Down Expand Up @@ -80,6 +83,10 @@ kqueue_modify (EV_P_ int fd, int oev, int nev)

if (nev & EV_WRITE)
kqueue_change (EV_A_ fd, EVFILT_WRITE, EV_ADD | EV_ENABLE, NOTE_EOF);

if (nev & EV_LIBUV_KQUEUE_HACK)
kqueue_change (EV_A_ fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_ONESHOT,
NOTE_ATTRIB | NOTE_WRITE | NOTE_RENAME | NOTE_DELETE | NOTE_EXTEND | NOTE_REVOKE);
}

static void
Expand Down Expand Up @@ -114,6 +121,13 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
{
int fd = kqueue_events [i].ident;

if (kqueue_events [i].filter == EVFILT_VNODE)
{
/* pass kqueue filter flags to libuv */
ev_io *w = (ev_io *)(anfds [fd].head);
uv__kqueue_hack (EV_A_ kqueue_events [i].fflags, w);
}

if (expect_false (kqueue_events [i].flags & EV_ERROR))
{
int err = kqueue_events [i].data;
Expand All @@ -140,6 +154,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
fd,
kqueue_events [i].filter == EVFILT_READ ? EV_READ
: kqueue_events [i].filter == EVFILT_WRITE ? EV_WRITE
: kqueue_events [i].filter == EVFILT_VNODE ? EV_LIBUV_KQUEUE_HACK
: 0
);
}
Expand Down
40 changes: 32 additions & 8 deletions deps/uv/src/unix/freebsd.c
Expand Up @@ -25,6 +25,7 @@
#include <errno.h>

#include <sys/types.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <time.h>

Expand Down Expand Up @@ -67,16 +68,39 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}

double uv_get_free_memory(void) {
vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);

int uv_fs_event_init(uv_loop_t* loop,
uv_fs_event_t* handle,
const char* filename,
uv_fs_event_cb cb) {
uv__set_sys_error(loop, ENOSYS);
return -1;
if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) {
return -1;
}

return (double) info.free_count * sysconf(_SC_PAGESIZE);
}

double uv_get_total_memory(void) {
unsigned long info;
int which[] = {CTL_HW, HW_PHYSMEM};

size_t size = sizeof(info);

if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
return -1;
}

return (double) info;
}

void uv_loadavg(double avg[3]) {
struct loadavg info;
size_t size = sizeof(info);
int which[] = {CTL_VM, VM_LOADAVG};

if (sysctl(which, 2, &info, &size, NULL, 0) < 0) return;

void uv__fs_event_destroy(uv_fs_event_t* handle) {
assert(0 && "implement me");
avg[0] = (double) info.ldavg[0] / info.fscale;
avg[1] = (double) info.ldavg[1] / info.fscale;
avg[2] = (double) info.ldavg[2] / info.fscale;
}
22 changes: 13 additions & 9 deletions deps/uv/src/unix/internal.h
Expand Up @@ -32,33 +32,37 @@
#include <linux/version.h>
#include <features.h>

#undef HAVE_FUTIMES
#undef HAVE_PIPE2
#undef HAVE_ACCEPT4

/* futimes() requires linux >= 2.6.22 and glib >= 2.6 */
#if LINUX_VERSION_CODE >= 0x20616 && __GLIBC_PREREQ(2, 6)
#define HAVE_FUTIMES
#define HAVE_FUTIMES 1
#endif

/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */
#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9)
#define HAVE_PIPE2
#define HAVE_PIPE2 1
#endif

/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */
#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10)
#define HAVE_ACCEPT4
#define HAVE_ACCEPT4 1
#endif

#endif /* __linux__ */

#ifdef __APPLE__
# define HAVE_FUTIMES
# define HAVE_FUTIMES 1
#endif

#ifdef __FreeBSD__
# define HAVE_FUTIMES
# define HAVE_FUTIMES 1
#endif

/* FIXME exact copy of the #ifdef guard in uv-unix.h */
#if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) \
|| defined(__FreeBSD__) \
|| defined(__OpenBSD__) \
|| defined(__NetBSD__)
# define HAVE_KQUEUE 1
#endif

#define container_of(ptr, type, member) \
Expand Down

0 comments on commit 627f379

Please sign in to comment.