On Win32, use GetSystemTimeAsFileTime() instead of GetTickCount().

2005-03-20  Tor Lillqvist  <tml@novell.com>

	* glib/gtimer.c: On Win32, use GetSystemTimeAsFileTime() instead
	of GetTickCount(). (#159507)
This commit is contained in:
Tor Lillqvist 2005-03-20 11:57:20 +00:00 committed by Tor Lillqvist
parent 24b14aa184
commit 69aae7e623
5 changed files with 24 additions and 19 deletions

View File

@ -5,6 +5,9 @@
helper process. helper process.
(g_spawn_sync): Don't ask for a child pid which we don't need. (g_spawn_sync): Don't ask for a child pid which we don't need.
* glib/gtimer.c: On Win32, use GetSystemTimeAsFileTime() instead
of GetTickCount(). (#159507)
2005-03-17 Matthias Clasen <mclasen@redhat.com> 2005-03-17 Matthias Clasen <mclasen@redhat.com>
* glib/gkeyfile.c: Update the documentation, reflecting the * glib/gkeyfile.c: Update the documentation, reflecting the

View File

@ -5,6 +5,9 @@
helper process. helper process.
(g_spawn_sync): Don't ask for a child pid which we don't need. (g_spawn_sync): Don't ask for a child pid which we don't need.
* glib/gtimer.c: On Win32, use GetSystemTimeAsFileTime() instead
of GetTickCount(). (#159507)
2005-03-17 Matthias Clasen <mclasen@redhat.com> 2005-03-17 Matthias Clasen <mclasen@redhat.com>
* glib/gkeyfile.c: Update the documentation, reflecting the * glib/gkeyfile.c: Update the documentation, reflecting the

View File

@ -5,6 +5,9 @@
helper process. helper process.
(g_spawn_sync): Don't ask for a child pid which we don't need. (g_spawn_sync): Don't ask for a child pid which we don't need.
* glib/gtimer.c: On Win32, use GetSystemTimeAsFileTime() instead
of GetTickCount(). (#159507)
2005-03-17 Matthias Clasen <mclasen@redhat.com> 2005-03-17 Matthias Clasen <mclasen@redhat.com>
* glib/gkeyfile.c: Update the documentation, reflecting the * glib/gkeyfile.c: Update the documentation, reflecting the

View File

@ -5,6 +5,9 @@
helper process. helper process.
(g_spawn_sync): Don't ask for a child pid which we don't need. (g_spawn_sync): Don't ask for a child pid which we don't need.
* glib/gtimer.c: On Win32, use GetSystemTimeAsFileTime() instead
of GetTickCount(). (#159507)
2005-03-17 Matthias Clasen <mclasen@redhat.com> 2005-03-17 Matthias Clasen <mclasen@redhat.com>
* glib/gkeyfile.c: Update the documentation, reflecting the * glib/gkeyfile.c: Update the documentation, reflecting the

View File

@ -52,8 +52,8 @@
struct _GTimer struct _GTimer
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
DWORD start; guint64 start;
DWORD end; guint64 end;
#else /* !G_OS_WIN32 */ #else /* !G_OS_WIN32 */
struct timeval start; struct timeval start;
struct timeval end; struct timeval end;
@ -64,7 +64,7 @@ struct _GTimer
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
# define GETTIME(v) \ # define GETTIME(v) \
v = GetTickCount () GetSystemTimeAsFileTime ((FILETIME *)&v)
#else /* !G_OS_WIN32 */ #else /* !G_OS_WIN32 */
# define GETTIME(v) \ # define GETTIME(v) \
gettimeofday (&v, NULL) gettimeofday (&v, NULL)
@ -123,7 +123,7 @@ void
g_timer_continue (GTimer *timer) g_timer_continue (GTimer *timer)
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
DWORD elapsed; guint64 elapsed;
#else #else
struct timeval elapsed; struct timeval elapsed;
#endif /* G_OS_WIN32 */ #endif /* G_OS_WIN32 */
@ -176,7 +176,9 @@ g_timer_elapsed (GTimer *timer,
gulong *microseconds) gulong *microseconds)
{ {
gdouble total; gdouble total;
#ifndef G_OS_WIN32 #ifdef G_OS_WIN32
gint64 elapsed;
#else
struct timeval elapsed; struct timeval elapsed;
#endif /* G_OS_WIN32 */ #endif /* G_OS_WIN32 */
@ -184,23 +186,14 @@ g_timer_elapsed (GTimer *timer,
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (timer->active) if (timer->active)
timer->end = GetTickCount (); GETTIME (timer->end);
/* Check for wraparound, which happens every 49.7 days. */ elapsed = timer->end - timer->start;
if (timer->end < timer->start)
total = (UINT_MAX - (timer->start - timer->end - 1)) / 1000.0; total = elapsed / 1e7;
else
total = (timer->end - timer->start) / 1000.0;
if (microseconds) if (microseconds)
{ *microseconds = (elapsed / 10) % 1000000;
if (timer->end < timer->start)
*microseconds =
((UINT_MAX - (timer->start - timer->end - 1)) % 1000) * 1000;
else
*microseconds =
((timer->end - timer->start) % 1000) * 1000;
}
#else /* !G_OS_WIN32 */ #else /* !G_OS_WIN32 */
if (timer->active) if (timer->active)
gettimeofday (&timer->end, NULL); gettimeofday (&timer->end, NULL);