From: Jarkko Hietaniemi Date: Thu, 12 Apr 2001 01:34:46 +0000 (+0000) Subject: Integrate Time::Hires 1.20 from Douglas E. Wegscheid. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dcf686c9ff9829ff83c8d4e65b735a4ba6a9e6f5;p=p5sagit%2Fp5-mst-13.2.git Integrate Time::Hires 1.20 from Douglas E. Wegscheid. p4raw-id: //depot/perl@9690 --- diff --git a/MANIFEST b/MANIFEST index d9d5176..a9196bb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -485,6 +485,10 @@ ext/Thread/unsync.t Test thread implicit synchronisation ext/Thread/unsync2.t Test thread implicit synchronisation ext/Thread/unsync3.t Test thread implicit synchronisation ext/Thread/unsync4.t Test thread implicit synchronisation +ext/Time/HiRes/Changes Time::HiRes +ext/Time/HiRes/HiRes.pm Time::HiRes +ext/Time/HiRes/HiRes.xs Time::HiRes +ext/Time/HiRes/Makefile.PL Time::HiRes ext/XS/Typemap/Makefile.PL XS::Typemap extension ext/XS/Typemap/README XS::Typemap extension ext/XS/Typemap/Typemap.pm XS::Typemap extension @@ -1601,6 +1605,7 @@ t/lib/tie-stdarray.t Test for Tie::StdArray t/lib/tie-stdhandle.t Test for Tie::StdHandle t/lib/tie-stdpush.t Test for Tie::StdArray t/lib/tie-substrhash.t Test for Tie::SubstrHash +t/lib/time-hires.t Time::HiRes t/lib/timelocal.t See if Time::Local works t/lib/trig.t See if Math::Trig works t/lib/xs-typemap.t test that typemaps work diff --git a/ext/Time/HiRes/Changes b/ext/Time/HiRes/Changes new file mode 100644 index 0000000..16fc027 --- /dev/null +++ b/ext/Time/HiRes/Changes @@ -0,0 +1,99 @@ +Revision history for Perl extension Time::HiRes. + +1.20 Wed Feb 24 21:30 1999 + - make our usleep and ualarm substitutes into hrt_usleep + and hrt_ualarm. This helps static links of Perl with other + packages that also have usleep, etc. From + Ilya Zakharevich + - add C API stuff. From Joshua Pritikin + + - VMS Makefile.PL fun. From pvhp@forte.com (Peter Prymmer) + - hopefully correct "-lc" fix for SCO. + - add PPD stuff + +1.19 Tue Sep 29 22:30 1998 + - put VMS gettimeofday() in. Patch is from Sebastian Bazley + + - change GIMME_V to GIMME to help people with older versions of + Perl. + - fix Win32 version of gettimeofday(). It didn't affect anything, + but it confuses people reading the code when the return value + is backwards (0 is success). + - fix Makefile.PL (more) so that detection of gettimeofday is + more correct. + +1.18 Mon Jul 6 22:40 1998 + - add usleep() for Win32. + - fix Makefile.PL to fix reported HP/UX feature where unresolved + externals still cause an executable to be generated (though no + x bit set). Thanks to David Kozinn for report and explanation. + Problems with the fix are mine :) + +1.17 Wed Jul 1 20:10 1998 + - fix setitimer calls so microseconds is not more than 1000000. + Hp/UX 9 doesn't like that. Provided by Roland B Robert, PhD. + - make Win32. We only get gettimeofday (the select hack doesn't + seem to work on my Win95 system). + - fix test 4 on 01test.t. add test to see if time() and + Time::HiRes::time() are close. + +1.16 Wed Nov 12 21:05 1997 + - add missing EXTEND in new gettimeofday scalar code. + +1.15 Mon Nov 10 21:30 1997 + - HiRes.pm: update pod. Provided by Gisle Aas. + - HiRes.xs: if gettimeofday() called in scalar context, do + something more useful than before. Provided by Gisle Aas. + - README: tell of xsubpp '-nolinenumber' woes. thanks to + Edward Henigin for pointing out the problem. + +1.14 Wed Nov 5 9:40 1997 + - Makefile.PL: look for setitimer + - HiRes.xs: if missing ualarm, but we have setitimer, make up + our own setitimer. These were provided by Gisle Aas. + +1.13 Tue Nov 4 23:30 1997 + - Makefile.PL: fix autodetect mechanism to do try linking in addition + to just compiling; should fix Linux build problem. Fix was provided + by Gisle Aas. + +1.12 Sun Oct 12 12:00:00 1997 + - Makefile.PL: set XSOPT to '-nolinenumbers' to work around xsubpp bug; + you may need to comment this back out if you have an older xsubpp. + - HiRes.xs: set PROTOTYPES: DISABLE + +1.11 Fri Sep 05 16:00:00 1997 + - Makefile.PL: + Had some line commented out that shouldn't have been (testing + remnants) + - README: + Previous version was corrupted. + +1.10 Thu May 22 20:20:00 1997 + - HiRes.xs, HiRes.pm, t/*: + - only compile what we have OS support for (or can + fake with select()) + - only test what we compiled + - gross improvement to the test suite + - fix EXPORT_FAIL. + This work was all done by Roderick Schertler + . If you run Linux or + one of the other ualarm-less platoforms, and you like this + module, let Roderick know; without him, it still wouldn't + be working on those boxes... + - Makefile.PL: figure out what routines the OS has and + only build what we need. These bits were written by Jarkko + Hietaniemi . Again, gratitude is due... + +1.02 Mon Dec 30 08:00:00 1996 + - HiRes.pm: update documentation to say what to do when missing + ualarm() and friends. + - README: update to warn that ualarm() and friends need to exist + +1.01 Fri Oct 17 08:00:00 1996 + - Makefile.PL: make XSPROTOARGS => '-noprototyopes' + - HiRes.pm: put blank line between __END__ and =head1 so that + pod2man works. + +1.00 Tue Sep 03 13:00:00 1996 + - original version; created by h2xs 1.16 diff --git a/ext/Time/HiRes/HiRes.pm b/ext/Time/HiRes/HiRes.pm new file mode 100644 index 0000000..0bc152b --- /dev/null +++ b/ext/Time/HiRes/HiRes.pm @@ -0,0 +1,255 @@ +package Time::HiRes; + +use strict; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK @EXPORT_FAIL); + +require Exporter; +require DynaLoader; + +@ISA = qw(Exporter DynaLoader); + +@EXPORT = qw( ); +@EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval); + +$VERSION = do{my@r=q$Revision: 1.20 $=~/\d+/g;sprintf '%02d.'.'%02d'x$#r,@r}; + +bootstrap Time::HiRes $VERSION; + +@EXPORT_FAIL = grep { ! defined &$_ } @EXPORT_OK; + +# Preloaded methods go here. + +sub tv_interval { + # probably could have been done in C + my ($a, $b) = @_; + $b = [gettimeofday()] unless defined($b); + (${$b}[0] - ${$a}[0]) + ((${$b}[1] - ${$a}[1]) / 1_000_000); +} + +# I'm only supplying this because the version of it in 5.003's Export.pm +# is buggy (it doesn't shift off the class name). + +sub export_fail { + my $self = shift; + @_; +} + +# Autoload methods go after =cut, and are processed by the autosplit program. + +1; +__END__ + +=head1 NAME + +Time::HiRes - High resolution ualarm, usleep, and gettimeofday + +=head1 SYNOPSIS + + use Time::HiRes qw( usleep ualarm gettimeofday tv_interval ); + + usleep ($microseconds); + + ualarm ($microseconds); + ualarm ($microseconds, $interval_microseconds); + + $t0 = [gettimeofday]; + ($seconds, $microseconds) = gettimeofday; + + $elapsed = tv_interval ( $t0, [$seconds, $microseconds]); + $elapsed = tv_interval ( $t0, [gettimeofday]); + $elapsed = tv_interval ( $t0 ); + + use Time::HiRes qw ( time alarm sleep ); + $now_fractions = time; + sleep ($floating_seconds); + alarm ($floating_seconds); + alarm ($floating_seconds, $floating_interval); + +=head1 DESCRIPTION + +The C module implements a Perl interface to the usleep, ualarm, +and gettimeofday system calls. See the EXAMPLES section below and the test +scripts for usage; see your system documentation for the description of +the underlying gettimeofday, usleep, and ualarm calls. + +If your system lacks gettimeofday(2) you don't get gettimeofday() or the +one-arg form of tv_interval(). If you don't have usleep(3) or select(2) +you don't get usleep() or sleep(). If your system don't have ualarm(3) +or setitimer(2) you don't +get ualarm() or alarm(). If you try to import an unimplemented function +in the C statement it will fail at compile time. + +The following functions can be imported from this module. No +functions are exported by default. + +=over 4 + +=item gettimeofday () + +In array context it returns a 2 element array with the seconds and +microseconds since the epoch. In scalar context it returns floating +seconds like Time::HiRes::time() (see below). + +=item usleep ( $useconds ) + +Issues a usleep for the number of microseconds specified. See also +Time::HiRes::sleep() below. + +=item ualarm ( $useconds [, $interval_useconds ] ) + +Issues a ualarm call; interval_useconds is optional and will be 0 if +unspecified, resulting in alarm-like behaviour. + +=item tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] ) + +Returns the floating seconds between the two times, which should have been +returned by gettimeofday(). If the second argument is omitted, then the +current time is used. + +=item time () + +Returns a floating seconds since the epoch. This function can be imported, +resulting in a nice drop-in replacement for the C