summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-03 19:59:11 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-03 19:59:11 +0000
commit712439b530685c222ac72df818cecef1b8b5b430 (patch)
tree437f8940f9ea77894ef1ae90e6d0e1f88c88e04f /thread.c
parent9ee7578937b5b83cc55ad2071b87ccba5c117f8d (diff)
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
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c17
1 files changed, 12 insertions, 5 deletions
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;
}