From: Mikko Rasa Date: Thu, 9 Jun 2011 08:38:40 +0000 (+0300) Subject: Make Time::sleep void X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=62a984b46e08740d19cb055f01be3365982f6b9d;p=libs%2Fcore.git Make Time::sleep void Check return value of nanosleep internally and throw if necessary --- diff --git a/source/time/utils.cpp b/source/time/utils.cpp index 123b2d9..7da0aed 100644 --- a/source/time/utils.cpp +++ b/source/time/utils.cpp @@ -3,7 +3,9 @@ #else #include #include +#include #endif +#include #include "datetime.h" #include "timedelta.h" #include "timestamp.h" @@ -71,14 +73,15 @@ TimeDelta get_cpu_time() /** Sleeps for the given time. */ -int sleep(const TimeDelta &d) +void sleep(const TimeDelta &d) { #ifndef WIN32 timespec ts = d; - return nanosleep(&ts, 0); + while(nanosleep(&ts, 0)==-1) + if(errno!=EINTR) + throw system_error("nanosleep"); #else Sleep((DWORD)(d/msec)); - return 0; #endif } diff --git a/source/time/utils.h b/source/time/utils.h index 2916559..0a2b351 100644 --- a/source/time/utils.h +++ b/source/time/utils.h @@ -12,7 +12,7 @@ class TimeStamp; extern TimeStamp now(); extern std::string format_now(const std::string &); extern TimeDelta get_cpu_time(); -extern int sleep(const TimeDelta &); +extern void sleep(const TimeDelta &); } // namespace Time } // namespace Msp