]> git.tdb.fi Git - libs/core.git/commitdiff
Isolate platform-dependent RawTime conversion functions to a private header
authorMikko Rasa <tdb@tdb.fi>
Fri, 29 Jul 2011 22:17:04 +0000 (01:17 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 29 Jul 2011 22:17:04 +0000 (01:17 +0300)
source/core/semaphore.cpp
source/time/rawtime.cpp
source/time/rawtime.h
source/time/rawtime_private.h [new file with mode: 0644]
source/time/timedelta.h
source/time/timestamp.h
source/time/utils.cpp

index e923ca8835efb7e3e7b59e4afd2f6ec4e92c078e..8fa1be90f7c7e234abde3e74409bfb916acbffb9 100644 (file)
@@ -4,6 +4,7 @@
 #include <sys/time.h>
 #include <cerrno>
 #endif
+#include <msp/time/rawtime_private.h>
 #include <msp/time/timestamp.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
@@ -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)
index 427eb335b29102edf5c67a4137647fcb743bc76f..5c21a683ce295a026b6bd8e4f970950e2d952aba 100644 (file)
@@ -1,4 +1,5 @@
 #include "rawtime.h"
+#include "rawtime_private.h"
 
 namespace Msp {
 namespace Time {
index 4831645adb60f8d0ea401b5bc4486dbb10ad6d1b..76524509990986fd55b0eaa78a9cd366bee95c00 100644 (file)
@@ -1,10 +1,6 @@
 #ifndef MSP_TIME_RAWTIME_H_
 #define MSP_TIME_RAWTIME_H_
 
-#ifndef WIN32
-#include <sys/time.h>
-#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 (file)
index 0000000..566d5a6
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef MSP_TIME_RAWTIME_PRIVATE_H_
+#define MSP_TIME_RAWTIME_PRIVATE_H_
+
+#ifndef WIN32
+#include <sys/time.h>
+#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
index 972ee26387406d224b11bf3f77f76b4c88fdd296..4a5411838dff02ab761d7b9f696fa6515b38c6f0 100644 (file)
@@ -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; }
 };
 
index 41fc1e58dbe448b7de8d3f98468dc403e41c6f92..1317b26bc0ba067c7774ef9ecfd6fb7342e2bdff 100644 (file)
@@ -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); }
 };
 
index d69febcb0a52a2326b2f7cf05c39cc92e18607a2..b59a8af0ea944fdde78cf77d4ee5c38cf4b6aa15 100644 (file)
@@ -7,6 +7,7 @@
 #endif
 #include <msp/core/systemerror.h>
 #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");