summaryrefslogtreecommitdiff
path: root/deps/uv/src
diff options
context:
space:
mode:
authorSaúl Ibarra Corretgé <saghul@gmail.com>2015-09-11 17:55:29 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2015-09-11 18:38:43 +0200
commit68dc69a382692f424c53b75724e684a406b195a1 (patch)
treeae2725deaaea798d3b61e2258ad329016f0b3ddd /deps/uv/src
parent958a94e19dd6dda962cd690a5f4aa0ad02ac21bc (diff)
downloadandroid-node-v8-68dc69a382692f424c53b75724e684a406b195a1.tar.gz
android-node-v8-68dc69a382692f424c53b75724e684a406b195a1.tar.bz2
android-node-v8-68dc69a382692f424c53b75724e684a406b195a1.zip
deps: update libuv to version 1.7.4
PR-URL: https://github.com/nodejs/node/pull/2817 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/uv/src')
-rw-r--r--deps/uv/src/unix/freebsd.c14
-rw-r--r--deps/uv/src/unix/fs.c9
-rw-r--r--deps/uv/src/unix/process.c7
-rw-r--r--deps/uv/src/win/thread.c92
-rw-r--r--deps/uv/src/win/tty.c38
5 files changed, 94 insertions, 66 deletions
diff --git a/deps/uv/src/unix/freebsd.c b/deps/uv/src/unix/freebsd.c
index c838beb28e..c69608b139 100644
--- a/deps/uv/src/unix/freebsd.c
+++ b/deps/uv/src/unix/freebsd.c
@@ -240,17 +240,13 @@ error:
int uv_uptime(double* uptime) {
- time_t now;
- struct timeval info;
- size_t size = sizeof(info);
- static int which[] = {CTL_KERN, KERN_BOOTTIME};
-
- if (sysctl(which, 2, &info, &size, NULL, 0))
+ int r;
+ struct timespec sp;
+ r = clock_gettime(CLOCK_MONOTONIC, &sp);
+ if (r)
return -errno;
- now = time(NULL);
-
- *uptime = (double)(now - info.tv_sec);
+ *uptime = sp.tv_sec;
return 0;
}
diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c
index 52082e9347..d739c28258 100644
--- a/deps/uv/src/unix/fs.c
+++ b/deps/uv/src/unix/fs.c
@@ -574,7 +574,14 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) {
r = sendfile(in_fd, out_fd, req->off, &len, NULL, 0);
#endif
- if (r != -1 || len != 0) {
+ /*
+ * The man page for sendfile(2) on DragonFly states that `len` contains
+ * a meaningful value ONLY in case of EAGAIN and EINTR.
+ * Nothing is said about it's value in case of other errors, so better
+ * not depend on the potential wrong assumption that is was not modified
+ * by the syscall.
+ */
+ if (r == 0 || ((errno == EAGAIN || errno == EINTR) && len != 0)) {
req->off += len;
return (ssize_t) len;
}
diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c
index f2a83753ee..9fa061e6bc 100644
--- a/deps/uv/src/unix/process.c
+++ b/deps/uv/src/unix/process.c
@@ -226,13 +226,14 @@ static int uv__process_open_stream(uv_stdio_container_t* container,
int pipefds[2],
int writable) {
int flags;
+ int err;
if (!(container->flags & UV_CREATE_PIPE) || pipefds[0] < 0)
return 0;
- if (uv__close(pipefds[1]))
- if (errno != EINTR && errno != EINPROGRESS)
- abort();
+ err = uv__close(pipefds[1]);
+ if (err != 0 && err != -EINPROGRESS)
+ abort();
pipefds[1] = -1;
uv__nonblock(pipefds[0], 1);
diff --git a/deps/uv/src/win/thread.c b/deps/uv/src/win/thread.c
index d7171fd690..bacceab95f 100644
--- a/deps/uv/src/win/thread.c
+++ b/deps/uv/src/win/thread.c
@@ -396,18 +396,16 @@ static void uv__rwlock_srwlock_wrunlock(uv_rwlock_t* rwlock) {
static int uv__rwlock_fallback_init(uv_rwlock_t* rwlock) {
- int err;
-
- err = uv_mutex_init(&rwlock->fallback_.read_mutex_);
- if (err)
- return err;
+ /* Initialize the semaphore that acts as the write lock. */
+ HANDLE handle = CreateSemaphoreW(NULL, 1, 1, NULL);
+ if (handle == NULL)
+ return uv_translate_sys_error(GetLastError());
+ rwlock->fallback_.write_lock_.sem = handle;
- err = uv_mutex_init(&rwlock->fallback_.write_mutex_);
- if (err) {
- uv_mutex_destroy(&rwlock->fallback_.read_mutex_);
- return err;
- }
+ /* Initialize the critical section protecting the reader count. */
+ InitializeCriticalSection(&rwlock->fallback_.read_lock_.cs);
+ /* Initialize the reader count. */
rwlock->fallback_.num_readers_ = 0;
return 0;
@@ -415,64 +413,88 @@ static int uv__rwlock_fallback_init(uv_rwlock_t* rwlock) {
static void uv__rwlock_fallback_destroy(uv_rwlock_t* rwlock) {
- uv_mutex_destroy(&rwlock->fallback_.read_mutex_);
- uv_mutex_destroy(&rwlock->fallback_.write_mutex_);
+ DeleteCriticalSection(&rwlock->fallback_.read_lock_.cs);
+ CloseHandle(rwlock->fallback_.write_lock_.sem);
}
static void uv__rwlock_fallback_rdlock(uv_rwlock_t* rwlock) {
- uv_mutex_lock(&rwlock->fallback_.read_mutex_);
-
- if (++rwlock->fallback_.num_readers_ == 1)
- uv_mutex_lock(&rwlock->fallback_.write_mutex_);
+ /* Acquire the lock that protects the reader count. */
+ EnterCriticalSection(&rwlock->fallback_.read_lock_.cs);
+
+ /* Increase the reader count, and lock for write if this is the first
+ * reader.
+ */
+ if (++rwlock->fallback_.num_readers_ == 1) {
+ DWORD r = WaitForSingleObject(rwlock->fallback_.write_lock_.sem, INFINITE);
+ if (r != WAIT_OBJECT_0)
+ uv_fatal_error(GetLastError(), "WaitForSingleObject");
+ }
- uv_mutex_unlock(&rwlock->fallback_.read_mutex_);
+ /* Release the lock that protects the reader count. */
+ LeaveCriticalSection(&rwlock->fallback_.read_lock_.cs);
}
static int uv__rwlock_fallback_tryrdlock(uv_rwlock_t* rwlock) {
int err;
- err = uv_mutex_trylock(&rwlock->fallback_.read_mutex_);
- if (err)
- goto out;
+ if (!TryEnterCriticalSection(&rwlock->fallback_.read_lock_.cs))
+ return UV_EAGAIN;
err = 0;
- if (rwlock->fallback_.num_readers_ == 0)
- err = uv_mutex_trylock(&rwlock->fallback_.write_mutex_);
-
- if (err == 0)
- rwlock->fallback_.num_readers_++;
-
- uv_mutex_unlock(&rwlock->fallback_.read_mutex_);
+ if (rwlock->fallback_.num_readers_ == 0) {
+ DWORD r = WaitForSingleObject(rwlock->fallback_.write_lock_.sem, 0);
+ if (r == WAIT_OBJECT_0)
+ rwlock->fallback_.num_readers_++;
+ else if (r == WAIT_TIMEOUT)
+ err = UV_EAGAIN;
+ else if (r == WAIT_FAILED)
+ err = uv_translate_sys_error(GetLastError());
+ else
+ err = UV_EIO;
+ }
-out:
+ LeaveCriticalSection(&rwlock->fallback_.read_lock_.cs);
return err;
}
static void uv__rwlock_fallback_rdunlock(uv_rwlock_t* rwlock) {
- uv_mutex_lock(&rwlock->fallback_.read_mutex_);
+ EnterCriticalSection(&rwlock->fallback_.read_lock_.cs);
- if (--rwlock->fallback_.num_readers_ == 0)
- uv_mutex_unlock(&rwlock->fallback_.write_mutex_);
+ if (--rwlock->fallback_.num_readers_ == 0) {
+ if (!ReleaseSemaphore(rwlock->fallback_.write_lock_.sem, 1, NULL))
+ uv_fatal_error(GetLastError(), "ReleaseSemaphore");
+ }
- uv_mutex_unlock(&rwlock->fallback_.read_mutex_);
+ LeaveCriticalSection(&rwlock->fallback_.read_lock_.cs);
}
static void uv__rwlock_fallback_wrlock(uv_rwlock_t* rwlock) {
- uv_mutex_lock(&rwlock->fallback_.write_mutex_);
+ DWORD r = WaitForSingleObject(rwlock->fallback_.write_lock_.sem, INFINITE);
+ if (r != WAIT_OBJECT_0)
+ uv_fatal_error(GetLastError(), "WaitForSingleObject");
}
static int uv__rwlock_fallback_trywrlock(uv_rwlock_t* rwlock) {
- return uv_mutex_trylock(&rwlock->fallback_.write_mutex_);
+ DWORD r = WaitForSingleObject(rwlock->fallback_.write_lock_.sem, 0);
+ if (r == WAIT_OBJECT_0)
+ return 0;
+ else if (r == WAIT_TIMEOUT)
+ return UV_EAGAIN;
+ else if (r == WAIT_FAILED)
+ return uv_translate_sys_error(GetLastError());
+ else
+ return UV_EIO;
}
static void uv__rwlock_fallback_wrunlock(uv_rwlock_t* rwlock) {
- uv_mutex_unlock(&rwlock->fallback_.write_mutex_);
+ if (!ReleaseSemaphore(rwlock->fallback_.write_lock_.sem, 1, NULL))
+ uv_fatal_error(GetLastError(), "ReleaseSemaphore");
}
diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c
index c3af02f7f2..b40bb42710 100644
--- a/deps/uv/src/win/tty.c
+++ b/deps/uv/src/win/tty.c
@@ -1498,6 +1498,11 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
} \
} while (0)
+#define ENSURE_BUFFER_SPACE(wchars_needed) \
+ if (wchars_needed > ARRAY_SIZE(utf16_buf) - utf16_buf_used) { \
+ FLUSH_TEXT(); \
+ }
+
/* Cache for fast access */
unsigned char utf8_bytes_left = handle->tty.wr.utf8_bytes_left;
unsigned int utf8_codepoint = handle->tty.wr.utf8_codepoint;
@@ -1881,32 +1886,29 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
}
if (utf8_codepoint == 0x0a || utf8_codepoint == 0x0d) {
- /* EOL conversion - emit \r\n, when we see either \r or \n. */
- /* If a \n immediately follows a \r or vice versa, ignore it. */
- if (previous_eol == 0 || utf8_codepoint == previous_eol) {
- /* If there's no room in the utf16 buf, flush it first. */
- if (2 > ARRAY_SIZE(utf16_buf) - utf16_buf_used) {
- uv_tty_emit_text(handle, utf16_buf, utf16_buf_used, error);
- utf16_buf_used = 0;
- }
+ /* EOL conversion - emit \r\n when we see \n. */
+ if (utf8_codepoint == 0x0a && previous_eol != 0x0d) {
+ /* \n was not preceded by \r; print \r\n. */
+ ENSURE_BUFFER_SPACE(2);
utf16_buf[utf16_buf_used++] = L'\r';
utf16_buf[utf16_buf_used++] = L'\n';
- previous_eol = (char) utf8_codepoint;
+ } else if (utf8_codepoint == 0x0d && previous_eol == 0x0a) {
+ /* \n was followed by \r; do not print the \r, since */
+ /* the source was either \r\n\r (so the second \r is */
+ /* redundant) or was \n\r (so the \n was processed */
+ /* by the last case and an \r automatically inserted). */
} else {
- /* Ignore this newline, but don't ignore later ones. */
- previous_eol = 0;
+ /* \r without \n; print \r as-is. */
+ ENSURE_BUFFER_SPACE(1);
+ utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint;
}
+ previous_eol = (char) utf8_codepoint;
+
} else if (utf8_codepoint <= 0xffff) {
/* Encode character into utf-16 buffer. */
-
- /* If there's no room in the utf16 buf, flush it first. */
- if (1 > ARRAY_SIZE(utf16_buf) - utf16_buf_used) {
- uv_tty_emit_text(handle, utf16_buf, utf16_buf_used, error);
- utf16_buf_used = 0;
- }
-
+ ENSURE_BUFFER_SPACE(1);
utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint;
previous_eol = 0;
}