core: Float::sleep to handle interruptions
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 2 Feb 2017 19:48:21 +0000 (14:48 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 2 Feb 2017 21:33:36 +0000 (16:33 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/core/time.nit

index 74c9818..999f1e9 100644 (file)
@@ -26,19 +26,24 @@ fun get_time: Int `{ return time(NULL); `}
 
 redef class Sys
        # Wait a specific number of second and nanoseconds
-       fun nanosleep(sec, nanosec: Int) `{
+       #
+       # Returns `true` if interrupted by a signal.
+       fun nanosleep(sec, nanosec: Int): Bool `{
                const struct timespec req = {sec, nanosec};
-               nanosleep(&req, NULL);
+               return nanosleep(&req, NULL);
        `}
 end
 
 redef class Float
        # Sleep approximately `self` seconds
+       #
+       # Is not interrupted by signals.
        fun sleep `{
                time_t s = self;
                long ns = (self-s) * 1000000000.0;
-               const struct timespec req = {s, ns};
-               nanosleep(&req, NULL);
+               struct timespec req = {s, ns};
+
+               while (nanosleep(&req, &req)) { }
        `}
 end