From a7e60b75765df7817f6c0f4e86b8939ba988e826 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 31 Aug 2000 20:55:16 +0000 Subject: [PATCH] Simplify, use GetSystemTimeAsFileTime(). 2000-08-31 Tor Lillqvist * gmain.c (g_get_current_time): (Win32): Simplify, use GetSystemTimeAsFileTime(). --- ChangeLog | 5 +++++ ChangeLog.pre-2-0 | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ ChangeLog.pre-2-12 | 5 +++++ ChangeLog.pre-2-2 | 5 +++++ ChangeLog.pre-2-4 | 5 +++++ ChangeLog.pre-2-6 | 5 +++++ ChangeLog.pre-2-8 | 5 +++++ glib/gmain.c | 25 +++++++------------------ gmain.c | 25 +++++++------------------ 10 files changed, 54 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index acc00a91..2bd25cde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index acc00a91..2bd25cde 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +2000-08-31 Tor Lillqvist + + * gmain.c (g_get_current_time): (Win32): Simplify, use + GetSystemTimeAsFileTime(). + 2000-08-27 Tor Lillqvist * giowin32.c (g_io_channel_win32_poll): New function, otherwise diff --git a/glib/gmain.c b/glib/gmain.c index 0258570f..dafd09a4 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -629,26 +629,15 @@ g_get_current_time (GTimeVal *result) result->tv_sec = r.tv_sec; result->tv_usec = r.tv_usec; #else - /* Avoid calling time() except for the first time. - * GetTickCount() should be pretty fast and low-level? - * I could also use ftime() but it seems unnecessarily overheady. - */ - static DWORD start_tick = 0; - static time_t start_time; - DWORD tick; - - g_return_if_fail (result != NULL); - - if (start_tick == 0) - { - start_tick = GetTickCount (); - time (&start_time); - } + FILETIME filetime; + gint64 t; - tick = GetTickCount (); + GetSystemTimeAsFileTime (&filetime); + t = ((gint64) filetime.dwLowDateTime) + + ((gint64) filetime.dwHighDateTime) * G_GINT64_CONSTANT (0x100000000); - result->tv_sec = (tick - start_tick) / 1000 + start_time; - result->tv_usec = ((tick - start_tick) % 1000) * 1000; + result->tv_sec = (t - G_GINT64_CONSTANT (0x19db1ded53e8000)) / 10000000; + result->tv_usec = (t % 10000000) / 10; #endif } diff --git a/gmain.c b/gmain.c index 0258570f..dafd09a4 100644 --- a/gmain.c +++ b/gmain.c @@ -629,26 +629,15 @@ g_get_current_time (GTimeVal *result) result->tv_sec = r.tv_sec; result->tv_usec = r.tv_usec; #else - /* Avoid calling time() except for the first time. - * GetTickCount() should be pretty fast and low-level? - * I could also use ftime() but it seems unnecessarily overheady. - */ - static DWORD start_tick = 0; - static time_t start_time; - DWORD tick; - - g_return_if_fail (result != NULL); - - if (start_tick == 0) - { - start_tick = GetTickCount (); - time (&start_time); - } + FILETIME filetime; + gint64 t; - tick = GetTickCount (); + GetSystemTimeAsFileTime (&filetime); + t = ((gint64) filetime.dwLowDateTime) + + ((gint64) filetime.dwHighDateTime) * G_GINT64_CONSTANT (0x100000000); - result->tv_sec = (tick - start_tick) / 1000 + start_time; - result->tv_usec = ((tick - start_tick) % 1000) * 1000; + result->tv_sec = (t - G_GINT64_CONSTANT (0x19db1ded53e8000)) / 10000000; + result->tv_usec = (t % 10000000) / 10; #endif } -- 2.34.1