X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FTime%2FHiRes%2FHiRes.pm;h=72eed1c4a5da801bf94d73a6ee71d1d179e0021f;hb=0225372c57036b54771b8abce5d6355b7e7ed288;hp=11848dbf27c1df1237e8a32ea09e3eab99cb01c3;hpb=3c72ec0095d5296c829ece3ce089509b7f8a14ab;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Time/HiRes/HiRes.pm b/ext/Time/HiRes/HiRes.pm index 11848db..72eed1c 100644 --- a/ext/Time/HiRes/HiRes.pm +++ b/ext/Time/HiRes/HiRes.pm @@ -1,27 +1,30 @@ package Time::HiRes; use strict; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use vars qw($VERSION $XS_VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); require Exporter; -use XSLoader; +require DynaLoader; -@ISA = qw(Exporter); +@ISA = qw(Exporter DynaLoader); @EXPORT = qw( ); @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval - getitimer setitimer ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF); - -$VERSION = '1.21'; + getitimer setitimer + ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF + d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer + d_nanosleep); + +$VERSION = '1.54'; +$XS_VERSION = $VERSION; +$VERSION = eval $VERSION; sub AUTOLOAD { my $constname; - ($constname= $AUTOLOAD) =~ s/.*:://; - my $val = constant($constname, @_ ? $_[0] : 0); - if ($!) { - my ($pack,$file,$line) = caller; - die "Your vendor has not defined Time::HiRes macro $constname, used at $file line $line.\n"; - } + ($constname = $AUTOLOAD) =~ s/.*:://; + die "&Time::HiRes::constant not defined" if $constname eq 'constant'; + my ($error, $val) = constant($constname); + if ($error) { die $error; } { no strict 'refs'; *$AUTOLOAD = sub { $val }; @@ -29,7 +32,7 @@ sub AUTOLOAD { goto &$AUTOLOAD; } -XSLoader::load 'Time::HiRes', $VERSION; +bootstrap Time::HiRes; # Preloaded methods go here. @@ -47,7 +50,7 @@ __END__ =head1 NAME -Time::HiRes - High resolution ualarm, usleep, and gettimeofday +Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers =head1 SYNOPSIS @@ -73,25 +76,43 @@ Time::HiRes - High resolution ualarm, usleep, and gettimeofday alarm ($floating_seconds, $floating_interval); use Time::HiRes qw( setitimer getitimer - ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ); + ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF ); setitimer ($which, $floating_seconds, $floating_interval ); getitimer ($which); =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. +The C module implements a Perl interface to the C, +C, C, and C/C system calls, in other +words, high resolution time and timers. See the L section below +and the test scripts for usage; see your system documentation for the +description of the underlying C or C, C, +C, and C/C calls. + +If your system lacks C or an emulation of it you don't +get C or the one-argument form of C. If your system lacks all of +C, C, and C, you don't get +C or C. If your system lacks both +C and C you don't get +C or C. -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. +If your subsecond sleeping is implemented with C instead of +C, you can mix subsecond sleeping with signals since +C does not use signals. This, however is unportable, and you +should first check for the truth value of C<&Time::HiRes::d_nanosleep> to +see whether you have nanosleep, and then carefully read your +C C API documentation for any peculiarities. (There is no +separate interface to call C; just use C +or C with small enough values.) + +Unless using C for mixing sleeping with signals, give +some thought to whether Perl is the tool you should be using for work +requiring nanosecond accuracies. + The following functions can be imported from this module. No functions are exported by default. @@ -99,91 +120,126 @@ No functions are exported by default. =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). +In array context returns a two-element array with the seconds and +microseconds since the epoch. In scalar context returns floating +seconds like C (see below). =item usleep ( $useconds ) -Issues a usleep for the number of microseconds specified. See also -Time::HiRes::sleep() below. +Sleeps for the number of microseconds specified. Returns the number +of microseconds actually slept. Can sleep for more than one second, +unlike the C system call. See also C 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. +Issues a C call; the C<$interval_useconds> is optional and +will be zero if unspecified, resulting in C-like behaviour. + +=item tv_interval -=item tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] ) +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. +Returns the floating seconds between the two times, which should have +been returned by C. 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