From: Mikko Rasa Date: Fri, 29 Jul 2011 22:17:04 +0000 (+0300) Subject: Isolate platform-dependent RawTime conversion functions to a private header X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=03bacb2343eb5d17819732582c0866f087e9ce27;p=libs%2Fcore.git Isolate platform-dependent RawTime conversion functions to a private header --- diff --git a/source/core/semaphore.cpp b/source/core/semaphore.cpp index e923ca8..8fa1be9 100644 --- a/source/core/semaphore.cpp +++ b/source/core/semaphore.cpp @@ -4,6 +4,7 @@ #include #include #endif +#include #include #include #include @@ -85,7 +86,7 @@ bool Semaphore::wait(const Time::TimeDelta &d) throw system_error("Semaphore::wait"); return ret==WAIT_OBJECT_0; #else - timespec timeout = Time::now()+d; + timespec timeout = Time::rawtime_to_timespec((Time::now()+d).raw()); int err = pthread_cond_timedwait(&priv->cond, &priv->mutex.priv->mutex, &timeout); if(err && err!=ETIMEDOUT) diff --git a/source/time/rawtime.cpp b/source/time/rawtime.cpp index 427eb33..5c21a68 100644 --- a/source/time/rawtime.cpp +++ b/source/time/rawtime.cpp @@ -1,4 +1,5 @@ #include "rawtime.h" +#include "rawtime_private.h" namespace Msp { namespace Time { diff --git a/source/time/rawtime.h b/source/time/rawtime.h index 4831645..7652450 100644 --- a/source/time/rawtime.h +++ b/source/time/rawtime.h @@ -1,10 +1,6 @@ #ifndef MSP_TIME_RAWTIME_H_ #define MSP_TIME_RAWTIME_H_ -#ifndef WIN32 -#include -#endif - namespace Msp { namespace Time { @@ -14,12 +10,6 @@ typedef __int64 RawTime; typedef long long RawTime; #endif -#ifndef WIN32 -// Internal conversion utilities, not intended for public use -timeval rawtime_to_timeval(RawTime); -timespec rawtime_to_timespec(RawTime); -#endif - } // namespace Time } // namespace Msp diff --git a/source/time/rawtime_private.h b/source/time/rawtime_private.h new file mode 100644 index 0000000..566d5a6 --- /dev/null +++ b/source/time/rawtime_private.h @@ -0,0 +1,21 @@ +#ifndef MSP_TIME_RAWTIME_PRIVATE_H_ +#define MSP_TIME_RAWTIME_PRIVATE_H_ + +#ifndef WIN32 +#include +#endif +#include "rawtime.h" + +namespace Msp { +namespace Time { + +#ifndef WIN32 +// Internal conversion utilities, not intended for public use +timeval rawtime_to_timeval(RawTime); +timespec rawtime_to_timespec(RawTime); +#endif + +} // namespace Time +} // namespace Msp + +#endif diff --git a/source/time/timedelta.h b/source/time/timedelta.h index 972ee26..4a54118 100644 --- a/source/time/timedelta.h +++ b/source/time/timedelta.h @@ -53,11 +53,6 @@ public: bool operator==(const TimeDelta &t) const { return usec==t.usec; } bool operator!=(const TimeDelta &t) const { return usec!=t.usec; } -#ifndef WIN32 - operator timeval() const { return rawtime_to_timeval(usec); } - operator timespec() const { return rawtime_to_timespec(usec); } -#endif - operator const void *() const { return usec ? this : 0; } }; diff --git a/source/time/timestamp.h b/source/time/timestamp.h index 41fc1e5..1317b26 100644 --- a/source/time/timestamp.h +++ b/source/time/timestamp.h @@ -48,11 +48,6 @@ public: operator const void *() const { return usec>0 ? this : 0; } -#ifndef WIN32 - operator timeval() const { return rawtime_to_timeval(usec); } - operator timespec() const { return rawtime_to_timespec(usec); } -#endif - static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); } }; diff --git a/source/time/utils.cpp b/source/time/utils.cpp index d69febc..b59a8af 100644 --- a/source/time/utils.cpp +++ b/source/time/utils.cpp @@ -7,6 +7,7 @@ #endif #include #include "datetime.h" +#include "rawtime_private.h" #include "timedelta.h" #include "timestamp.h" #include "units.h" @@ -67,7 +68,7 @@ TimeDelta get_cpu_time() void sleep(const TimeDelta &d) { #ifndef WIN32 - timespec ts = d; + timespec ts = rawtime_to_timespec(d.raw()); while(nanosleep(&ts, 0)==-1) if(errno!=EINTR) throw system_error("nanosleep");