=item usleep ( $useconds )
Issues a usleep for the number of microseconds specified. Returns the
-number of microseconds actually slept. The number of microseconds
-B<must> be between 0 and 1_000_0000 (inclusive): you B<cannot> sleep
-a minute by usleep(60_000_000). See also Time::HiRes::sleep() below.
+number of microseconds actually slept. See also Time::HiRes::sleep()
+below.
=item ualarm ( $useconds [, $interval_useconds ] )
$SIG{VTALRM} = 'DEFAULT';
}
-$a = abs(sleep(1) - 1);
+$a = abs(sleep(1.5) - 1.5);
print $a < 0.1 ? "ok 20 # $a\n" : "not ok 20 # $a\n";
-$a = abs(usleep(1000000) / 1000000 - 1);
+$a = abs(usleep(1_500_000) / 1_500_000 - 1.0);
print $a < 0.1 ? "ok 21 # $a\n" : "not ok 21 # $a\n";
#if defined(HAS_USLEEP) && defined(HAS_GETTIMEOFDAY)
-int
+NV
usleep(useconds)
- int useconds
+ NV useconds
PREINIT:
struct timeval Ta, Tb;
CODE:
gettimeofday(&Ta, NULL);
if (items > 0) {
- if (useconds > 1000000)
- croak("usleep: useconds must be between 0 and 1000000 (inclusive)");
- usleep(useconds);
+ if (useconds > 1E6) {
+ IV seconds = (IV) (useconds / 1E6);
+ sleep(seconds);
+ useconds -= 1E6 * seconds;
+ }
+ usleep((UV)useconds);
} else
PerlProc_pause();
gettimeofday(&Tb, NULL);
- RETVAL = 1000000*(Tb.tv_sec-Ta.tv_sec)+(Tb.tv_usec-Ta.tv_usec);
+#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);
OUTPUT:
RETVAL
struct timeval Ta, Tb;
CODE:
gettimeofday(&Ta, NULL);
- if (items > 0)
- usleep((int)(SvNV(ST(0)) * 1000000));
- else
+ if (items > 0) {
+ NV seconds = SvNV(ST(0));
+ IV useconds = 1E6 * (seconds - (IV)seconds);
+ sleep(seconds);
+ usleep(useconds);
+ } else
PerlProc_pause();
gettimeofday(&Tb, NULL);
+#if 0
+ printf("[%ld %ld] [%ld %ld]\n", Tb.tv_sec, Tb.tv_usec, Ta.tv_sec, Ta.tv_usec);
+#endif
RETVAL = (NV)(Tb.tv_sec-Ta.tv_sec)+0.000001*(NV)(Tb.tv_usec-Ta.tv_usec);
OUTPUT: