Merge pull request #2721 from ludovic-henry/fix-mono_ms_ticks
[mono.git] / mono / utils / mono-time.c
index 5f0168ebb7475b94886d44a002331d2aa1184842..5a34f440353e0d8ff72b83443b42412b7d5dda0a 100644 (file)
 #include <utils/mono-time.h>
 
 
-#define MTICKS_PER_SEC 10000000
+#define MTICKS_PER_SEC (10 * 1000 * 1000)
+
+gint64
+mono_msec_ticks (void)
+{
+       return mono_100ns_ticks () / 10 / 1000;
+}
 
 #ifdef HOST_WIN32
 #include <windows.h>
 
-guint32
-mono_msec_ticks (void)
+#ifndef _MSC_VER
+/* we get "error: implicit declaration of function 'GetTickCount64'" */
+ULONGLONG GetTickCount64(void);
+#endif
+
+gint64
+mono_msec_boottime (void)
 {
        /* GetTickCount () is reportedly monotonic */
-       return GetTickCount ();
+       return GetTickCount64 ();
 }
 
 /* Returns the number of 100ns ticks from unspecified time: this should be monotonic */
@@ -114,8 +125,8 @@ get_boot_time (void)
 }
 
 /* Returns the number of milliseconds from boot time: this should be monotonic */
-guint32
-mono_msec_ticks (void)
+gint64
+mono_msec_boottime (void)
 {
        static gint64 boot_time = 0;
        gint64 now;
@@ -123,6 +134,7 @@ mono_msec_ticks (void)
                boot_time = get_boot_time ();
        now = mono_100ns_ticks ();
        /*printf ("now: %llu (boot: %llu) ticks: %llu\n", (gint64)now, (gint64)boot_time, (gint64)(now - boot_time));*/
+       g_assert (now > boot_time);
        return (now - boot_time)/10000;
 }