Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2009-05-07 19:41:08 +0400
committerJeffrey Stedfast <fejj@novell.com>2009-05-07 19:41:08 +0400
commit6bb1704a2d07605a8f21c84532573e492e6acc92 (patch)
tree5d4b8f1ca5c0f1a7bbfefbf2605a92b087ec16b7 /eglib
parentbc1d2d5356aebbdae0ad1d3d2e8cee6c3399a6f9 (diff)
2009-04-22 Jeffrey Stedfast <fejj@novell.com>
* src/gtimer-win32.c (g_timer_elapsed): Avoid re-querying freq by just saving it in a static variable. Also modified microseconds calculation to avoid overflow. svn path=/trunk/mono/; revision=133725
Diffstat (limited to 'eglib')
-rw-r--r--eglib/ChangeLog6
-rw-r--r--eglib/src/gtimer-win32.c22
2 files changed, 19 insertions, 9 deletions
diff --git a/eglib/ChangeLog b/eglib/ChangeLog
index f7c08f6fa9b..a1aeb06629a 100644
--- a/eglib/ChangeLog
+++ b/eglib/ChangeLog
@@ -1,3 +1,9 @@
+2009-04-22 Jeffrey Stedfast <fejj@novell.com>
+
+ * src/gtimer-win32.c (g_timer_elapsed): Avoid re-querying freq by
+ just saving it in a static variable. Also modified microseconds
+ calculation to avoid overflow.
+
2009-04-05 Miguel de Icaza <miguel@novell.com>
* src/gpath.c: Avoid situations where we add the separator if one
diff --git a/eglib/src/gtimer-win32.c b/eglib/src/gtimer-win32.c
index f9418efa4a7..07e802bda13 100644
--- a/eglib/src/gtimer-win32.c
+++ b/eglib/src/gtimer-win32.c
@@ -68,9 +68,14 @@ g_timer_stop (GTimer *timer)
gdouble
g_timer_elapsed (GTimer *timer, gulong *microseconds)
{
- guint64 stop;
- guint64 freq;
- gdouble seconds;
+ static guint64 freq = 0;
+ guint64 delta, stop;
+
+ if (freq == 0) {
+ if (!QueryPerformanceFrequency ((LARGE_INTEGER *)&freq))
+ freq = 1;
+ }
+
if (timer->stop == 0) {
QueryPerformanceCounter ((LARGE_INTEGER*)&stop);
}
@@ -78,13 +83,12 @@ g_timer_elapsed (GTimer *timer, gulong *microseconds)
stop = timer->stop;
}
- QueryPerformanceFrequency ((LARGE_INTEGER*)&freq);
- seconds = 1.0 * (stop - timer->start) / freq;
+ delta = stop - timer->start;
- if (microseconds) {
- *microseconds = (gulong)(1000000.0 * (stop - timer->start) / freq);
- }
- return seconds;
+ if (microseconds)
+ *microseconds = (gulong) (delta * (1000000.0 / freq));
+
+ return (gdouble) delta / (gdouble) freq;
}