zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #17663
[Merge] lp:~paul-lucas/zorba/bug-855481 into lp:zorba
Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/bug-855481 into lp:zorba.
Commit message:
Fixed millisecond time for Windows.
Requested reviews:
Paul J. Lucas (paul-lucas)
Related bugs:
Bug #855481 in Zorba: "Too small time types on Windows"
https://bugs.launchpad.net/zorba/+bug/855481
For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/bug-855481/+merge/145740
Fixed millisecond time for Windows.
--
https://code.launchpad.net/~paul-lucas/zorba/bug-855481/+merge/145740
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/util/time.h'
--- include/zorba/util/time.h 2012-09-19 21:16:15 +0000
+++ include/zorba/util/time.h 2013-01-30 22:26:22 +0000
@@ -17,6 +17,8 @@
#ifndef ZORBA_UTIL_TIME_H
#define ZORBA_UTIL_TIME_H
+#include <zorba/config.h>
+
/**
* This header includes utility functions for certain timing-related
* operations, namely getting current wall-clock time and current
@@ -53,6 +55,13 @@
namespace time
{
+ // Large enough to hold number of milliseconds since epoch.
+#if ZORBA_SIZEOF_LONG <= 4
+ typedef long long msec_type;
+#else
+ typedef long msec_type;
+#endif /* ZORBA_SIZEOF_LONG */
+
//
//
// Types and functions for CPU time
@@ -139,12 +148,12 @@
clock_gettime(CLOCK_MONOTONIC, &t);
#else
clock_gettime(CLOCK_REALTIME, &t);
-#endif
+#endif /* _POSIX_MONOTONIC_CLOCK */
}
- inline long get_walltime_in_millis(const walltime& t)
+ inline msec_type get_walltime_in_millis(const walltime& t)
{
- return t.tv_sec * 1000 + t.tv_nsec / 1000000;
+ return t.tv_sec * (msec_type)1000 + t.tv_nsec / 1000000;
}
#elif defined(WIN32)
@@ -160,7 +169,7 @@
typedef struct timeb walltime;
#else
typedef struct _timeb walltime;
-#endif
+#endif /* WINCE */
inline double get_walltime_elapsed (const walltime& t0, const walltime& t1)
{
@@ -173,12 +182,12 @@
ftime(&t);
#else
_ftime_s(&t);
-#endif
+#endif /* WINCE */
}
- inline long get_walltime_in_millis(const walltime& t)
+ inline msec_type get_walltime_in_millis(const walltime& t)
{
- return (long)(t.time * 1000 + t.millitm);
+ return t.time * (msec_type)1000 + t.millitm;
}
#else /* not Windows, and no clock_gettime() */
@@ -199,19 +208,17 @@
gettimeofday(&t, NULL);
}
- inline long get_walltime_in_millis(const walltime& t)
+ inline msec_type get_walltime_in_millis(const walltime& t)
{
- return t.tv_sec * 1000 + t.tv_usec / 1000;
+ return t.tv_sec * (msec_type)1000 + t.tv_usec / 1000;
}
#endif /* ZORBA_HAVE_CLOCKGETTIME_FUNCTION */
- } // ::time
-
-} // ::zorba
-
-#endif
-
+ } // namespace time
+} // namesace zorba
+
+#endif /* ZORBA_UTIL_TIME_H */
/*
* Local variables:
* mode: c++
=== modified file 'include/zorba/util/timer.h'
--- include/zorba/util/timer.h 2012-09-19 21:16:15 +0000
+++ include/zorba/util/timer.h 2013-01-30 22:26:22 +0000
@@ -37,7 +37,7 @@
return get_walltime_elapsed(theStart, lEnd);
}
- long getStart() const {
+ time::msec_type getStart() const {
return get_walltime_in_millis(theStart);
}
=== modified file 'src/runtime/random/random_impl.cpp'
--- src/runtime/random/random_impl.cpp 2012-10-08 12:09:36 +0000
+++ src/runtime/random/random_impl.cpp 2013-01-30 22:26:22 +0000
@@ -105,7 +105,7 @@
{
store::Item_t num;
unsigned int int_seed;
- long walltime_millis;
+ time::msec_type walltime_millis;
uint32_t time_low;
zstring ltmp;
Follow ups