@@ -20,10 +20,11 @@ #define __NO_EXT_QNX #include #include +#include #ifndef _WIN32 # include #endif @@ -182,16 +183,26 @@ + (void)sleepForTimeInterval: (double)seconds { if (seconds < 0) @throw [OFOutOfRangeException exceptionWithClass: self]; -#ifndef _WIN32 +#if defined(HAVE_NANOSLEEP) + struct timespec rqtp; + + rqtp.tv_sec = (time_t)seconds; + rqtp.tv_nsec = lrint((seconds - rqtp.tv_sec) * 1000000000); + + if (rqtp.tv_sec != floor(seconds)) + @throw [OFOutOfRangeException exceptionWithClass: self]; + + nanosleep(&rqtp, NULL); +#elif !defined(_WIN32) if (seconds > UINT_MAX) @throw [OFOutOfRangeException exceptionWithClass: self]; sleep((unsigned int)seconds); - usleep((useconds_t)rint((seconds - floor(seconds)) * 1000000)); + usleep((useconds_t)lrint((seconds - floor(seconds)) * 1000000)); #else if (seconds * 1000 > UINT_MAX) @throw [OFOutOfRangeException exceptionWithClass: self]; Sleep((unsigned int)(seconds * 1000)); @@ -198,24 +209,11 @@ #endif } + (void)sleepUntilDate: (OFDate*)date { - double seconds = [date timeIntervalSinceNow]; - -#ifndef _WIN32 - if (seconds > UINT_MAX) - @throw [OFOutOfRangeException exceptionWithClass: self]; - - sleep((unsigned int)seconds); - usleep((useconds_t)rint((seconds - floor(seconds)) * 1000000)); -#else - if (seconds * 1000 > UINT_MAX) - @throw [OFOutOfRangeException exceptionWithClass: self]; - - Sleep((unsigned int)(seconds * 1000)); -#endif + [self sleepForTimeInterval: [date timeIntervalSinceNow]]; } + (void)yield { #ifdef OF_HAVE_SCHED_YIELD