summaryrefslogtreecommitdiff
path: root/deps/uv/test/runner-unix.c
diff options
context:
space:
mode:
authorSaúl Ibarra Corretgé <saghul@gmail.com>2015-08-05 21:17:46 +0200
committerthefourtheye <thechargingvolcano@gmail.com>2015-09-02 03:16:47 -0400
commita1615949a591fc523048a09540a2d340ff1b3da8 (patch)
tree1cc576ea6104f1baf8f92c6a82f3ca2b45afaccd /deps/uv/test/runner-unix.c
parente3740e452402892c1ce03bbbb4807e34f31558ad (diff)
downloadandroid-node-v8-a1615949a591fc523048a09540a2d340ff1b3da8.tar.gz
android-node-v8-a1615949a591fc523048a09540a2d340ff1b3da8.tar.bz2
android-node-v8-a1615949a591fc523048a09540a2d340ff1b3da8.zip
deps: upgrade libuv to 1.7.3
PR-URL: https://github.com/nodejs/node/pull/2310 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/uv/test/runner-unix.c')
-rw-r--r--deps/uv/test/runner-unix.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/deps/uv/test/runner-unix.c b/deps/uv/test/runner-unix.c
index 5da720fad4..2264d1e89d 100644
--- a/deps/uv/test/runner-unix.c
+++ b/deps/uv/test/runner-unix.c
@@ -37,6 +37,7 @@
#include <assert.h>
#include <sys/select.h>
+#include <sys/time.h>
#include <pthread.h>
@@ -173,6 +174,9 @@ int process_wait(process_info_t* vec, int n, int timeout) {
process_info_t* p;
dowait_args args;
pthread_t tid;
+ pthread_attr_t attr;
+ unsigned int elapsed_ms;
+ struct timeval timebase;
struct timeval tv;
fd_set fds;
@@ -199,20 +203,54 @@ int process_wait(process_info_t* vec, int n, int timeout) {
return -1;
}
- r = pthread_create(&tid, NULL, dowait, &args);
+ if (pthread_attr_init(&attr))
+ abort();
+
+ if (pthread_attr_setstacksize(&attr, 256 * 1024))
+ abort();
+
+ r = pthread_create(&tid, &attr, dowait, &args);
+
+ if (pthread_attr_destroy(&attr))
+ abort();
+
if (r) {
perror("pthread_create()");
retval = -1;
goto terminate;
}
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = 0;
+ if (gettimeofday(&timebase, NULL))
+ abort();
+
+ tv = timebase;
+ for (;;) {
+ /* Check that gettimeofday() doesn't jump back in time. */
+ assert(tv.tv_sec == timebase.tv_sec ||
+ (tv.tv_sec == timebase.tv_sec && tv.tv_usec >= timebase.tv_usec));
+
+ elapsed_ms =
+ (tv.tv_sec - timebase.tv_sec) * 1000 +
+ (tv.tv_usec / 1000) -
+ (timebase.tv_usec / 1000);
+
+ r = 0; /* Timeout. */
+ if (elapsed_ms >= (unsigned) timeout)
+ break;
- FD_ZERO(&fds);
- FD_SET(args.pipe[0], &fds);
+ tv.tv_sec = (timeout - elapsed_ms) / 1000;
+ tv.tv_usec = (timeout - elapsed_ms) % 1000 * 1000;
- r = select(args.pipe[0] + 1, &fds, NULL, NULL, &tv);
+ FD_ZERO(&fds);
+ FD_SET(args.pipe[0], &fds);
+
+ r = select(args.pipe[0] + 1, &fds, NULL, NULL, &tv);
+ if (!(r == -1 && errno == EINTR))
+ break;
+
+ if (gettimeofday(&tv, NULL))
+ abort();
+ }
if (r == -1) {
perror("select()");
@@ -229,15 +267,11 @@ int process_wait(process_info_t* vec, int n, int timeout) {
kill(p->pid, SIGTERM);
}
retval = -2;
-
- /* Wait for thread to finish. */
- r = pthread_join(tid, NULL);
- if (r) {
- perror("pthread_join");
- retval = -1;
- }
}
+ if (pthread_join(tid, NULL))
+ abort();
+
terminate:
close(args.pipe[0]);
close(args.pipe[1]);