This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Time::HiRes 1.69
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sun, 26 Jun 2005 20:06:10 +0000 (20:06 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sun, 26 Jun 2005 20:06:10 +0000 (20:06 +0000)
p4raw-id: //depot/perl@24985

ext/Time/HiRes/Changes
ext/Time/HiRes/HiRes.pm
ext/Time/HiRes/Makefile.PL

index 10b4243..5661bbc 100644 (file)
@@ -1,5 +1,18 @@
 Revision history for Perl extension Time::HiRes.
 
+1.69   - actually run a test for nanosleep since e.g. in AIX 4.2
+         it seems that one can link in nanosleep() but then calling
+         it fails instantly and sets errno to ENOSYS (Not implemented).
+         This may be fixable in the AIX case by figuring out the right
+         (realtime POSIX?) libs and whatnot, but in the general case
+         running a real test case is better.  (Of course, this change
+         will no doubt run into portability problems because of the
+         execution step...)
+         (from José Auguste-tienne)
+       - support XSLoader also since it's much faster
+         (from Alexey Tourbin)
+       - add SEE ALSO (BSD::Resource and Time::TAI64)
+
 1.68
        - somehow 1.67 had a lot of doubled lines (a major cut-and-paste
          error suspected), but miraculously it still worked since the
index f158830..a14dbb0 100644 (file)
@@ -7,6 +7,7 @@ require Exporter;
 require DynaLoader;
 
 @ISA = qw(Exporter DynaLoader);
+@ISA = qw(Exporter);
 
 @EXPORT = qw( );
 @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval
@@ -15,7 +16,7 @@ require DynaLoader;
                 d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
                 d_nanosleep);
        
-$VERSION = '1.68';
+$VERSION = '1.69';
 $XS_VERSION = $VERSION;
 $VERSION = eval $VERSION;
 
@@ -32,7 +33,15 @@ sub AUTOLOAD {
     goto &$AUTOLOAD;
 }
 
-bootstrap Time::HiRes;
+eval {
+    require XSLoader;
+    XSLoader::load('Time::HiRes', $XS_VERSION);
+    1;
+} or do {
+    require DynaLoader;
+    local @ISA = qw(DynaLoader);
+    bootstrap Time::HiRes $XS_VERSION;
+};
 
 # Preloaded methods go here.
 
@@ -363,6 +372,10 @@ platforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily
 drift off from the system clock (and the original time())  by up to 0.5
 seconds. Time::HiRes will notice this eventually and recalibrate.
 
+=head1 SEE ALSO
+
+L<BSD::Resource>, L<Time::TAI64>.
+
 =head1 AUTHORS
 
 D. Wegscheid <wegscd@whirlpool.com>
index 51bf35a..fe547ab 100644 (file)
@@ -135,11 +135,24 @@ sub try_compile_and_link {
            printf "cccmd = $cccmd\n" if $VERBOSE;
            my $res = system($cccmd);
            $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
+
+           if ( $ok && exists $args{run} && $args{run}) {
+               my $abs_tmp_exe =
+                   File::Spec->
+                       catfile(File::Spec->rel2abs(File::Spec->curdir),
+                               $tmp_exe);
+               printf "Running $abs_tmp_exe..." if $VERBOSE;
+               if (system($abs_tmp_exe) == 0) {
+                   $ok = $? == 0;
+               } else {
+                   print "system('$abs_tmp_exe') failed: $?\n";
+               }
+           }
            unlink("$tmp.c", $tmp_exe);
         }
     }
 
-    $ok;
+    return $ok;
 }
 
 sub has_gettimeofday {
@@ -202,6 +215,29 @@ EOM
     return 0;
 }
 
+sub has_nanosleep {
+    return 1 if
+    try_compile_and_link(<<EOM, run => 1);
+#include <time.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/* int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); */
+
+int main() {
+    struct timespec ts1, ts2;
+    ts1.tv_sec  = 0;
+    ts1.tv_nsec = 750000000;
+    ts2.tv_sec  = 0;
+    ts2.tv_nsec = 0;
+    nanosleep(&ts1, &ts2); /* E.g. in AIX nanosleep() might return ENOSYS. */
+    exit(errno);
+}
+EOM
+}
+
 sub has_include {
     my ($inc) = @_;
     return 1 if
@@ -344,7 +380,7 @@ EOD
            $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
        }
     } elsif ($^O ne 'mpeix' && # MPE/iX falsely finds nanosleep.
-             has_x ("nanosleep (NULL, NULL)")) {
+             has_nanosleep()) {
        $has_nanosleep++;
        $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
     }