From bc0b14063f97b7a15357c88472cad59a3f433648 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 8 Jul 2012 21:35:19 +1000 Subject: [PATCH] Cope with signals interrupting the nanosleep of nmsleep. --- util.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util.c b/util.c index 01cbb20b..c6b82048 100644 --- a/util.c +++ b/util.c @@ -692,9 +692,14 @@ void thr_info_cancel(struct thr_info *thr) * on SMP machines */ void nmsleep(unsigned int msecs) { - struct timespec twait; - - twait.tv_sec = msecs / 1000; - twait.tv_nsec = (uint64_t)(msecs * 1000000) - (uint64_t)(twait.tv_sec / 1000000000); - nanosleep(&twait, NULL); + struct timespec twait, tleft; + int ret; + + tleft.tv_sec = msecs / 1000; + tleft.tv_nsec = (uint64_t)(msecs * 1000000) - (uint64_t)(twait.tv_sec / 1000000000); + do { + twait.tv_sec = tleft.tv_sec; + twait.tv_nsec = tleft.tv_nsec; + ret = nanosleep(&twait, &tleft); + } while (ret == -1 && errno == EINTR); }