This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Time-HiRes: for nanosleeps, zero is success
authorJarkko Hietaniemi <jhi@iki.fi>
Thu, 3 Mar 2016 23:23:52 +0000 (18:23 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 4 Mar 2016 22:46:47 +0000 (17:46 -0500)
Testing for zero makes it slightly less odd-looking than bang.

dist/Time-HiRes/HiRes.xs

index 29c4c30..6133fc4 100644 (file)
@@ -975,7 +975,7 @@ nanosleep(nsec)
        sleepfor.tv_nsec = (long)(nsec - ((NV)sleepfor.tv_sec) * NV_1E9);
        unslept.tv_sec = 0;
        unslept.tv_nsec = 0;
-       if (!nanosleep(&sleepfor, &unslept)) {
+       if (nanosleep(&sleepfor, &unslept) == 0) {
            RETVAL = nsec;
        } else {
            sleepfor.tv_sec -= unslept.tv_sec;
@@ -1378,7 +1378,7 @@ clock_nanosleep(clock_id, nsec, flags = 0)
        sleepfor.tv_nsec = (long)(nsec - ((NV)sleepfor.tv_sec) * NV_1E9);
        unslept.tv_sec = 0;
        unslept.tv_nsec = 0;
-       if (!clock_nanosleep(clock_id, flags, &sleepfor, &unslept)) {
+       if (clock_nanosleep(clock_id, flags, &sleepfor, &unslept) == 0) {
            RETVAL = nsec;
        } else {
            sleepfor.tv_sec -= unslept.tv_sec;