From 712439b530685c222ac72df818cecef1b8b5b430 Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 3 Feb 2018 19:59:11 +0000 Subject: thread.c: extract timeval_sub from timeval_update_expire It can be useful on its own. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index fe5386a95d..a6d55f62e7 100644 --- a/thread.c +++ b/thread.c @@ -1160,6 +1160,16 @@ timeval_add(struct timeval *dst, const struct timeval *tv) } } +static void +timeval_sub(struct timeval *dst, const struct timeval *tv) +{ + dst->tv_sec -= tv->tv_sec; + if ((dst->tv_usec -= tv->tv_usec) < 0) { + --dst->tv_sec; + dst->tv_usec += 1000000; + } +} + static int timeval_update_expire(struct timeval *tv, const struct timeval *to) { @@ -1172,11 +1182,8 @@ timeval_update_expire(struct timeval *tv, const struct timeval *to) "%"PRI_TIMET_PREFIX"d.%.6ld > %"PRI_TIMET_PREFIX"d.%.6ld\n", (time_t)to->tv_sec, (long)to->tv_usec, (time_t)tvn.tv_sec, (long)tvn.tv_usec); - tv->tv_sec = to->tv_sec - tvn.tv_sec; - if ((tv->tv_usec = to->tv_usec - tvn.tv_usec) < 0) { - --tv->tv_sec; - tv->tv_usec += 1000000; - } + *tv = *to; + timeval_sub(tv, &tvn); return 0; } -- cgit v1.2.3