Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -571,16 +571,11 @@ AC_DEFINE(OF_HAVE_ATOMIC_OPS, 1, [Whether we have atomic operations]) AC_SUBST(ATOMIC_H, "atomic.h") ]) AC_MSG_RESULT($atomic_ops) -AC_CHECK_FUNC(gmtime_r, [ - AC_DEFINE(HAVE_GMTIME_R, 1, [Whether we have gmtime_r]) -]) -AC_CHECK_FUNC(localtime_r, [ - AC_DEFINE(HAVE_LOCALTIME_R, 1, [Whether we have localtime_r]) -]) +AC_CHECK_FUNCS([gmtime_r localtime_r nanosleep]) AC_ARG_ENABLE(sockets, AS_HELP_STRING([--disable-sockets], [disable socket support])) AS_IF([test x"$enable_sockets" != x"no"], [ AC_DEFINE(OF_HAVE_SOCKETS, 1, [Whether we have sockets]) Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -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 Index: src/exceptions/OFConditionBroadcastFailedException.h ================================================================== --- src/exceptions/OFConditionBroadcastFailedException.h +++ src/exceptions/OFConditionBroadcastFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFCondition; /*! * @brief An exception indicating broadcasting a condition failed. Index: src/exceptions/OFConditionSignalFailedException.h ================================================================== --- src/exceptions/OFConditionSignalFailedException.h +++ src/exceptions/OFConditionSignalFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFCondition; /*! * @brief An exception indicating signaling a condition failed. Index: src/exceptions/OFConditionStillWaitingException.h ================================================================== --- src/exceptions/OFConditionStillWaitingException.h +++ src/exceptions/OFConditionStillWaitingException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFCondition; /*! * @brief An exception indicating that a thread is still waiting for a Index: src/exceptions/OFConditionWaitFailedException.h ================================================================== --- src/exceptions/OFConditionWaitFailedException.h +++ src/exceptions/OFConditionWaitFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFCondition; /*! * @brief An exception indicating waiting for a condition failed. Index: src/exceptions/OFThreadJoinFailedException.h ================================================================== --- src/exceptions/OFThreadJoinFailedException.h +++ src/exceptions/OFThreadJoinFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFThread; /*! * @brief An exception indicating that joining a thread failed. Index: src/exceptions/OFThreadStartFailedException.h ================================================================== --- src/exceptions/OFThreadStartFailedException.h +++ src/exceptions/OFThreadStartFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFThread; /*! * @brief An exception indicating that starting a thread failed. Index: src/exceptions/OFThreadStillRunningException.h ================================================================== --- src/exceptions/OFThreadStillRunningException.h +++ src/exceptions/OFThreadStillRunningException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif @class OFThread; /*! * @brief An exception indicating that a thread is still running.