From a1615949a591fc523048a09540a2d340ff1b3da8 Mon Sep 17 00:00:00 2001 From: Saúl Ibarra Corretgé Date: Wed, 5 Aug 2015 21:17:46 +0200 Subject: deps: upgrade libuv to 1.7.3 PR-URL: https://github.com/nodejs/node/pull/2310 Reviewed-By: bnoordhuis - Ben Noordhuis Reviewed-By: cjihrig - Colin Ihrig --- deps/uv/test/runner-unix.c | 60 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'deps/uv/test/runner-unix.c') 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 #include +#include #include @@ -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]); -- cgit v1.2.3