dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20180202051837.14192-3-e@80x24.org> (raw)
In-Reply-To: <20180202051837.14192-1-e@80x24.org>

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


  parent reply	other threads:[~2018-02-02  5:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02  5:18 [PATCHv2 0/4] remove most FP from thread.c Eric Wong
2018-02-02  5:18 ` [PATCH 1/4] thread.c (rb_thread_terminate_all): eliminate double2timeval call Eric Wong
2018-02-02  5:18 ` Eric Wong [this message]
2018-02-02  5:18 ` [PATCH 3/4] thread.c: avoid FP for Thread#join Eric Wong
2018-02-02  5:18 ` [PATCH 4/4] thread.c: avoid FP in C-API time calculations Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180202051837.14192-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).