diff options
author | Saúl Ibarra Corretgé <saghul@gmail.com> | 2015-06-03 21:18:55 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-06-04 00:09:05 +0200 |
commit | aa33db32380fe05a3bc7a2e320bbf63a6adddf08 (patch) | |
tree | 6794c5f2c1a46e1e319f50860bf4b7d558b24587 /deps/uv/src/unix/linux-core.c | |
parent | a804026c9b5b9f8d6316fd5e9fdb9f96f7e1c6b3 (diff) | |
download | android-node-v8-aa33db32380fe05a3bc7a2e320bbf63a6adddf08.tar.gz android-node-v8-aa33db32380fe05a3bc7a2e320bbf63a6adddf08.tar.bz2 android-node-v8-aa33db32380fe05a3bc7a2e320bbf63a6adddf08.zip |
deps: update libuv to version 1.6.0
Fixes: https://github.com/joyent/node/issues/9310
PR-URL: https://github.com/nodejs/io.js/pull/1889
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/uv/src/unix/linux-core.c')
-rw-r--r-- | deps/uv/src/unix/linux-core.c | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/deps/uv/src/unix/linux-core.c b/deps/uv/src/unix/linux-core.c index d07494dd65..e6e68283d5 100644 --- a/deps/uv/src/unix/linux-core.c +++ b/deps/uv/src/unix/linux-core.c @@ -141,17 +141,26 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { void uv__io_poll(uv_loop_t* loop, int timeout) { + /* A bug in kernels < 2.6.37 makes timeouts larger than ~30 minutes + * effectively infinite on 32 bits architectures. To avoid blocking + * indefinitely, we cap the timeout and poll again if necessary. + * + * Note that "30 minutes" is a simplification because it depends on + * the value of CONFIG_HZ. The magic constant assumes CONFIG_HZ=1200, + * that being the largest value I have seen in the wild (and only once.) + */ + static const int max_safe_timeout = 1789569; static int no_epoll_pwait; static int no_epoll_wait; struct uv__epoll_event events[1024]; struct uv__epoll_event* pe; struct uv__epoll_event e; + int real_timeout; QUEUE* q; uv__io_t* w; sigset_t sigset; uint64_t sigmask; uint64_t base; - uint64_t diff; int nevents; int count; int nfds; @@ -209,8 +218,15 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { assert(timeout >= -1); base = loop->time; count = 48; /* Benchmarks suggest this gives the best throughput. */ + real_timeout = timeout; for (;;) { + /* See the comment for max_safe_timeout for an explanation of why + * this is necessary. Executive summary: kernel bug workaround. + */ + if (sizeof(int32_t) == sizeof(long) && timeout >= max_safe_timeout) + timeout = max_safe_timeout; + if (sigmask != 0 && no_epoll_pwait != 0) if (pthread_sigmask(SIG_BLOCK, &sigset, NULL)) abort(); @@ -244,6 +260,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { if (nfds == 0) { assert(timeout != -1); + + timeout = real_timeout - timeout; + if (timeout > 0) + continue; + return; } @@ -346,11 +367,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { update_timeout: assert(timeout > 0); - diff = loop->time - base; - if (diff >= (uint64_t) timeout) + real_timeout -= (loop->time - base); + if (real_timeout <= 0) return; - timeout -= diff; + timeout = real_timeout; } } @@ -523,7 +544,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { assert(numcpus != (unsigned int) -1); assert(numcpus != 0); - ci = calloc(numcpus, sizeof(*ci)); + ci = uv__calloc(numcpus, sizeof(*ci)); if (ci == NULL) return -ENOMEM; @@ -595,7 +616,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { if (model_idx < numcpus) { if (strncmp(buf, model_marker, sizeof(model_marker) - 1) == 0) { model = buf + sizeof(model_marker) - 1; - model = strndup(model, strlen(model) - 1); /* Strip newline. */ + model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */ if (model == NULL) { fclose(fp); return -ENOMEM; @@ -614,7 +635,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { #endif if (strncmp(buf, model_marker, sizeof(model_marker) - 1) == 0) { model = buf + sizeof(model_marker) - 1; - model = strndup(model, strlen(model) - 1); /* Strip newline. */ + model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */ if (model == NULL) { fclose(fp); return -ENOMEM; @@ -645,7 +666,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { inferred_model = ci[model_idx - 1].model; while (model_idx < numcpus) { - model = strndup(inferred_model, strlen(inferred_model)); + model = uv__strndup(inferred_model, strlen(inferred_model)); if (model == NULL) return -ENOMEM; ci[model_idx++].model = model; @@ -755,10 +776,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) { int i; for (i = 0; i < count; i++) { - free(cpu_infos[i].model); + uv__free(cpu_infos[i].model); } - free(cpu_infos); + uv__free(cpu_infos); } @@ -792,7 +813,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, if (*count == 0) return 0; - *addresses = malloc(*count * sizeof(**addresses)); + *addresses = uv__malloc(*count * sizeof(**addresses)); if (!(*addresses)) return -ENOMEM; @@ -812,7 +833,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, if (ent->ifa_addr->sa_family == PF_PACKET) continue; - address->name = strdup(ent->ifa_name); + address->name = uv__strdup(ent->ifa_name); if (ent->ifa_addr->sa_family == AF_INET6) { address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr); @@ -862,10 +883,10 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses, int i; for (i = 0; i < count; i++) { - free(addresses[i].name); + uv__free(addresses[i].name); } - free(addresses); + uv__free(addresses); } |