Merge pull request #2721 from ludovic-henry/fix-mono_ms_ticks
[mono.git] / mono / utils / mono-time.c
index 3c940e73ddfb85b82607dafd526cad6b388219aa..5a34f440353e0d8ff72b83443b42412b7d5dda0a 100644 (file)
@@ -2,6 +2,7 @@
  * Time utility functions.
  * Author: Paolo Molaro (<lupus@ximian.com>)
  * Copyright (C) 2008 Novell, Inc.
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
 #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 */
@@ -113,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;
@@ -122,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;
 }