Date: Thu, 2 Sep 1999 12:20:02 -0700 (PDT) From: "Kelly Yancey" <kbyanc@alcnet.com> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/13326: additional timeval interfaces for <sys/time.h> Message-ID: <199909021920.MAA65531@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/13326; it has been noted by GNATS. From: "Kelly Yancey" <kbyanc@alcnet.com> To: <freebsd-gnats-submit@freebsd.org>, <kbyanc@kronos.alcnet.com> Cc: Subject: Re: misc/13326: additional timeval interfaces for <sys/time.h> Date: Thu, 2 Sep 1999 15:14:00 -0400 Per Bruce's comments, here is a revised patch which rather than adding interfaces for obsolete timeval structures, instead makes the timespec operations available to user programs (basically just pulling them out of the #ifdef KERNEL restriction). In addition, I made 4 new interfaces including: multiplying and dividing timespec's by integral factors to get new timespecs converting timespecs to/from quad_t's representing raw nanosecond counts. The latter stemmed from a recent discussion on -current where Julian Elischer (Mon, 30 Aug 1999 17:10:03 -0700 (PDT), RE: HEADS UP) points out that working with timevals/timespecs is messy because of having to deal with 2 variables (actually, I've seen it griped about before, but this one made me feel like doing something about it :) ). In any event, the hope here is to make dealing with timespecs a little easier. If people need to deal with timevals, they are welcome to use TIMEVAL_TO_TIMESPEC and TIMESPEC_TO_TIMEVAL to convert to timespecs before doing the operations...or, of course, roll their own. Kelly ~kbyanc@posi.net~ FreeBSD - The Power To Serve - http://www.freebsd.org/ Join Team FreeBSD - http://www.posi.net/freebsd/Team-FreeBSD/ "The ultimate result of shielding men from the effects of folly is to fill the world with fools." - Herbert Spencer --- /usr/include/sys/time.h.orig Thu Sep 2 14:35:53 1999 +++ /usr/include/sys/time.h Thu Sep 2 14:55:59 1999 @@ -155,8 +155,6 @@ struct timecounter *tc_tweak; }; -#ifdef KERNEL - /* Operations on timespecs */ #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) @@ -182,6 +180,35 @@ (vvp)->tv_nsec += 1000000000; \ } \ } while (0) +#define timespecmul(tvp, uvp, x) \ + do { \ + (uvp)->tv_sec = (tvp)->tv_sec * x; \ + (uvp)->tv_nsec = (tvp)->tv_nsec * x; \ + while((uvp)->tv_nsec > 1000000000) { \ + (uvp)->tv_sec++; \ + (uvp)->tv_nsec -= 1000000000; \ + } \ + } while(0) +#define timespecdiv(tvp, uvp, x) \ + do { \ + (uvp)->tv_sec = (tvp)->tv_sec / x; \ + (uvp)->tv_nsec = (tvp)->tv_nsec / x; \ + } while(0) + +/* + * Operations for converting timespecs to/from quad_t's representing + * times in nanoseconds. + */ +#define tstoq(tvp, q) \ + do { \ + q = ((tvp)->tv_sec * 1000000000) + (tvp)->tv_nsec; \ + } while(0) +#define qtots(q, tvp) \ + do { \ + (tvp)->tv_sec = q / 1000000000; \ + (tvp)->tv_nsec = q % 1000000000; \ + } while(0) +#ifdef KERNEL /* Operations on timevals. */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909021920.MAA65531>