From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: ** X-Spam-ASN: AS58073 46.182.106.0/24 X-Spam-Status: No, score=2.3 required=3.0 tests=AWL,BAYES_00, RCVD_IN_BRBL_LASTEXT,RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL, SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (tor-exit.critical.cat [46.182.106.190]) by dcvr.yhbt.net (Postfix) with ESMTP id C04D01F404 for ; Fri, 2 Feb 2018 05:18:48 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 2/4] thread.c: extract timeval_sub from timeval_update_expire Date: Fri, 2 Feb 2018 05:18:35 +0000 Message-Id: <20180202051837.14192-3-e@80x24.org> In-Reply-To: <20180202051837.14192-1-e@80x24.org> References: <20180202051837.14192-1-e@80x24.org> List-Id: It can be useful on its own. --- thread.c | 17 ++++++++++++----- 1 file 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; } -- EW