Convert POSIX::sleep to an XS wrapper for PerlProc_sleep().
authorNicholas Clark <nick@ccl4.org>
Thu, 8 Dec 2011 15:46:21 +0000 (16:46 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 30 Dec 2011 10:36:39 +0000 (11:36 +0100)
Previously it was a Perl wrapper for CORE::sleep, converting CORE::sleep's
return value of elapsed time slept into the POSIX return value of seconds
remaining. However, that approach could sometimes return a negative result
if CORE::sleep had slept for more than a second longer than the requested
time.

ext/B/t/concise-xs.t
ext/POSIX/POSIX.xs
ext/POSIX/lib/POSIX.pm

index 9082f61..efd0cf7 100644 (file)
@@ -205,7 +205,7 @@ my $testpkgs = {
                      fmod floor dup2 dup difftime cuserid ctime
                      ctermid cosh constant close clock ceil
                      bootstrap atan asin asctime acos access abort
-                     _exit
+                     _exit sleep
                      /],
               },
 
index 1bad5e1..ab30a1c 100644 (file)
@@ -1885,6 +1885,14 @@ pause()
     CLEANUP:
     PERL_ASYNC_CHECK();
 
+unsigned int
+sleep(seconds)
+       unsigned int    seconds
+    CODE:
+       RETVAL = PerlProc_sleep(seconds);
+    OUTPUT:
+       RETVAL
+
 SysRet
 setgid(gid)
        Gid_t           gid
index 9840b76..b6997ff 100644 (file)
@@ -179,7 +179,6 @@ my %reimpl = (
     isatty    => 'filehandle => -t $_[0]',
     link      => 'oldfilename, newfilename => CORE::link($_[0], $_[1])',
     rmdir     => 'directoryname => CORE::rmdir($_[0])',
-    sleep     => 'seconds => $_[0] - CORE::sleep($_[0])',
     unlink    => 'filename => CORE::unlink($_[0])',
     utime     => 'filename, atime, mtime => CORE::utime($_[1], $_[2], $_[0])',
 );
@@ -391,7 +390,7 @@ our %EXPORT_TAGS = (
   # @EXPORT are actually shared hash key scalars, which will save some memory.
   our @EXPORT = keys %export;
 
-  our @EXPORT_OK = (qw(close lchown nice open pipe read times write
+  our @EXPORT_OK = (qw(close lchown nice open pipe read sleep times write
                       printf sprintf),
                    grep {!exists $export{$_}} keys %reimpl, keys %replacement);
 }