FAQ
In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/e3ff671b2bb1413760af7541e2213ef9543b2e8c?hp=9fbaf8bcf9b8d75e5110446b50b2c497b6678d90>

- Log -----------------------------------------------------------------
commit e3ff671b2bb1413760af7541e2213ef9543b2e8c
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date: Thu Mar 3 21:20:55 2016 -0500

     Time-HiRes: refactor also nanosleep init

M dist/Time-HiRes/HiRes.xs

commit ea21af8c42cbf6f433a9fb0cc5c489ebe9e4c11b
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date: Thu Mar 3 21:11:38 2016 -0500

     Time-HiRes: avoid going negative on struct timespec

M dist/Time-HiRes/HiRes.xs

commit 24e1662b30385499d57bc3afec35b6cbdc6ab973
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date: Thu Mar 3 21:25:30 2016 -0500

     Time-HiRes: refactor common timespec subtraction code

M dist/Time-HiRes/HiRes.xs

commit 6ac7c90092b06d57701515022affbfe531e33311
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date: Thu Mar 3 18:23:52 2016 -0500

     Time-HiRes: for nanosleeps, zero is success

     Testing for zero makes it slightly less odd-looking than bang.

M dist/Time-HiRes/HiRes.xs

commit de17b44fddc3c85d2d2d6a55383b9688267058c2
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date: Thu Mar 3 18:21:42 2016 -0500

     Time-HiRes: use NV_1E6 and NV_1E9 consistently

M dist/Time-HiRes/HiRes.xs

commit c8ea02b8bcc41d6561eff0b7dea8a4620d453cb0
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date: Thu Mar 3 17:29:58 2016 -0500

     Time-HiRes: initialize the unslept timespec

     Found by clang scan-build.

M dist/Time-HiRes/HiRes.xs
-----------------------------------------------------------------------

Summary of changes:
  dist/Time-HiRes/HiRes.xs | 81 +++++++++++++++++++++++++++++++-----------------
  1 file changed, 52 insertions(+), 29 deletions(-)

diff --git a/dist/Time-HiRes/HiRes.xs b/dist/Time-HiRes/HiRes.xs
index 304bad3..02909d7 100644
--- a/dist/Time-HiRes/HiRes.xs
+++ b/dist/Time-HiRes/HiRes.xs
@@ -896,6 +896,43 @@ static int clock_nanosleep(int clock_id, int flags,

  #include "const-c.inc"

+#if (defined(TIME_HIRES_NANOSLEEP)) || \
+ (defined(TIME_HIRES_CLOCK_NANOSLEEP) && defined(TIMER_ABSTIME))
+
+static void
+nanosleep_init(NV nsec,
+ struct timespec *sleepfor,
+ struct timespec *unslept) {
+ sleepfor->tv_sec = (Time_t)(nsec / NV_1E9);
+ sleepfor->tv_nsec = (long)(nsec - ((NV)sleepfor->tv_sec) * NV_1E9);
+ unslept->tv_sec = 0;
+ unslept->tv_nsec = 0;
+}
+
+static NV
+nsec_without_unslept(struct timespec *sleepfor,
+ const struct timespec *unslept) {
+ if (sleepfor->tv_sec >= unslept->tv_sec) {
+ sleepfor->tv_sec -= unslept->tv_sec;
+ if (sleepfor->tv_nsec >= unslept->tv_nsec) {
+ sleepfor->tv_nsec -= unslept->tv_nsec;
+ } else if (sleepfor->tv_sec > 0) {
+ sleepfor->tv_sec--;
+ sleepfor->tv_nsec += IV_1E9;
+ sleepfor->tv_nsec -= unslept->tv_nsec;
+ } else {
+ sleepfor->tv_sec = 0;
+ sleepfor->tv_nsec = 0;
+ }
+ } else {
+ sleepfor->tv_sec = 0;
+ sleepfor->tv_nsec = 0;
+ }
+ return ((NV)sleepfor->tv_sec) * NV_1E9 + ((NV)sleepfor->tv_nsec);
+}
+
+#endif
+
  MODULE = Time::HiRes PACKAGE = Time::HiRes

  PROTOTYPES: ENABLE
@@ -938,14 +975,14 @@ usleep(useconds)
   CODE:
   gettimeofday(&Ta, NULL);
   if (items > 0) {
- if (useconds >= 1E6) {
- IV seconds = (IV) (useconds / 1E6);
+ if (useconds >= NV_1E6) {
+ IV seconds = (IV) (useconds / NV_1E6);
    /* If usleep() has been implemented using setitimer()
     * then this contortion is unnecessary-- but usleep()
     * may be implemented in some other way, so let's contort. */
    if (seconds) {
        sleep(seconds);
- useconds -= 1E6 * seconds;
+ useconds -= NV_1E6 * seconds;
    }
       } else if (useconds < 0.0)
           croak("Time::HiRes::usleep(%"NVgf"): negative time not invented yet", useconds);
@@ -956,7 +993,7 @@ usleep(useconds)
  #if 0
   printf("[%ld %ld] [%ld %ld]\n", Tb.tv_sec, Tb.tv_usec, Ta.tv_sec, Ta.tv_usec);
  #endif
- RETVAL = 1E6*(Tb.tv_sec-Ta.tv_sec)+(NV)((IV)Tb.tv_usec-(IV)Ta.tv_usec);
+ RETVAL = NV_1E6*(Tb.tv_sec-Ta.tv_sec)+(NV)((IV)Tb.tv_usec-(IV)Ta.tv_usec);

   OUTPUT:
   RETVAL
@@ -971,18 +1008,11 @@ nanosleep(nsec)
   CODE:
   if (nsec < 0.0)
       croak("Time::HiRes::nanosleep(%"NVgf"): negative time not invented yet", nsec);
- sleepfor.tv_sec = (Time_t)(nsec / 1e9);
- sleepfor.tv_nsec = (long)(nsec - ((NV)sleepfor.tv_sec) * 1e9);
- if (!nanosleep(&sleepfor, &unslept)) {
+ nanosleep_init(nsec, &sleepfor, &unslept);
+ if (nanosleep(&sleepfor, &unslept) == 0) {
       RETVAL = nsec;
   } else {
- sleepfor.tv_sec -= unslept.tv_sec;
- sleepfor.tv_nsec -= unslept.tv_nsec;
- if (sleepfor.tv_nsec < 0) {
- sleepfor.tv_sec--;
- sleepfor.tv_nsec += 1000000000;
- }
- RETVAL = ((NV)sleepfor.tv_sec) * 1e9 + ((NV)sleepfor.tv_nsec);
+ RETVAL = nsec_without_unslept(&sleepfor, &unslept);
   }
      OUTPUT:
   RETVAL
@@ -1308,7 +1338,7 @@ clock_gettime(clock_id = CLOCK_REALTIME)
  #else
   status = clock_gettime(clock_id, &ts);
  #endif
- RETVAL = status == 0 ? ts.tv_sec + (NV) ts.tv_nsec / (NV) 1e9 : -1;
+ RETVAL = status == 0 ? ts.tv_sec + (NV) ts.tv_nsec / NV_1E9 : -1;

      OUTPUT:
   RETVAL
@@ -1341,7 +1371,7 @@ clock_getres(clock_id = CLOCK_REALTIME)
  #else
   status = clock_getres(clock_id, &ts);
  #endif
- RETVAL = status == 0 ? ts.tv_sec + (NV) ts.tv_nsec / (NV) 1e9 : -1;
+ RETVAL = status == 0 ? ts.tv_sec + (NV) ts.tv_nsec / NV_1E9 : -1;

      OUTPUT:
   RETVAL
@@ -1372,18 +1402,11 @@ clock_nanosleep(clock_id, nsec, flags = 0)
      CODE:
   if (nsec < 0.0)
       croak("Time::HiRes::clock_nanosleep(..., %"NVgf"): negative time not invented yet", nsec);
- sleepfor.tv_sec = (Time_t)(nsec / 1e9);
- sleepfor.tv_nsec = (long)(nsec - ((NV)sleepfor.tv_sec) * 1e9);
- if (!clock_nanosleep(clock_id, flags, &sleepfor, &unslept)) {
+ nanosleep_init(nsec, &sleepfor, &unslept);
+ if (clock_nanosleep(clock_id, flags, &sleepfor, &unslept) == 0) {
       RETVAL = nsec;
   } else {
- sleepfor.tv_sec -= unslept.tv_sec;
- sleepfor.tv_nsec -= unslept.tv_nsec;
- if (sleepfor.tv_nsec < 0) {
- sleepfor.tv_sec--;
- sleepfor.tv_nsec += 1000000000;
- }
- RETVAL = ((NV)sleepfor.tv_sec) * 1e9 + ((NV)sleepfor.tv_nsec);
+ RETVAL = nsec_without_unslept(&sleepfor, &unslept);
   }
      OUTPUT:
   RETVAL
@@ -1464,10 +1487,10 @@ PROTOTYPE: ;$
     UV ctime_nsec;
     hrstatns(&atime_nsec, &mtime_nsec, &ctime_nsec);
     if (atime_nsec)
- ST( 8) = sv_2mortal(newSVnv(atime + 1e-9 * (NV) atime_nsec));
+ ST( 8) = sv_2mortal(newSVnv(atime + (NV) atime_nsec / NV_1E9));
     if (mtime_nsec)
- ST( 9) = sv_2mortal(newSVnv(mtime + 1e-9 * (NV) mtime_nsec));
+ ST( 9) = sv_2mortal(newSVnv(mtime + (NV) mtime_nsec / NV_1E9));
     if (ctime_nsec)
- ST(10) = sv_2mortal(newSVnv(ctime + 1e-9 * (NV) ctime_nsec));
+ ST(10) = sv_2mortal(newSVnv(ctime + (NV) ctime_nsec / NV_1E9));
   }
   XSRETURN(nret);

--
Perl5 Master Repository

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupperl5-changes @
categoriesperl
postedMar 4, '16 at 10:56p
activeMar 4, '16 at 10:56p
posts1
users1
websiteperl.org

1 user in discussion

Jarkko Hietaniemi: 1 post

People

Translate

site design / logo © 2017 Grokbase