Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern ts2timo(9): refactor for clarity



details:   https://anonhg.NetBSD.org/src/rev/645028410666
branches:  trunk
changeset: 953709:645028410666
user:      nia <nia%NetBSD.org@localhost>
date:      Thu Mar 18 11:53:16 2021 +0000

description:
ts2timo(9): refactor for clarity

- 'flags' is not a boolean...
        - actually, it is, but it should simply be named "absolute".
        - convert tests for if (flags) to if (flags != TIMER_RELTIME)
- hoist function calls out of if expressions (requested by uwe)

still needs fixing:

- need to check for overflow before timespecsub.

diffstat:

 sys/kern/subr_time.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (44 lines):

diff -r 7d26f6c2c85d -r 645028410666 sys/kern/subr_time.c
--- a/sys/kern/subr_time.c      Thu Mar 18 01:50:12 2021 +0000
+++ b/sys/kern/subr_time.c      Thu Mar 18 11:53:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_time.c,v 1.25 2020/05/23 23:42:43 ad Exp $        */
+/*     $NetBSD: subr_time.c,v 1.26 2021/03/18 11:53:16 nia Exp $       */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.25 2020/05/23 23:42:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.26 2021/03/18 11:53:16 nia Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -332,18 +332,20 @@
        if (ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000L)
                return EINVAL;
 
-       flags &= TIMER_ABSTIME;
        if (start == NULL)
                start = &tsd;
 
-       if (flags || start != &tsd)
-               if ((error = clock_gettime1(clock_id, start)) != 0)
+       if (flags != TIMER_RELTIME || start != &tsd) {
+               error = clock_gettime1(clock_id, start);
+               if (error != 0)
                        return error;
+       }
 
-       if (flags)
+       if (flags != TIMER_RELTIME)
                timespecsub(ts, start, ts);
 
-       if ((error = itimespecfix(ts)) != 0)
+       error = itimespecfix(ts);
+       if (error != 0)
                return error;
 
        if (ts->tv_sec == 0 && ts->tv_nsec == 0)



Home | Main Index | Thread Index | Old Index