guint active : 1;
};
+#ifdef G_OS_WIN32
+# define GETTIME(v) \
+ v = GetTickCount ()
+#else /* !G_OS_WIN32 */
+# define GETTIME(v) \
+ gettimeofday (&v, NULL)
+#endif /* !G_OS_WIN32 */
+
GTimer*
g_timer_new (void)
{
timer = g_new (GRealTimer, 1);
timer->active = TRUE;
-#ifdef G_OS_WIN32
- timer->start = GetTickCount ();
-#else /* !G_OS_WIN32 */
- gettimeofday (&timer->start, NULL);
-#endif /* !G_OS_WIN32 */
+ GETTIME (timer->start);
return ((GTimer*) timer);
}
rtimer = (GRealTimer*) timer;
rtimer->active = TRUE;
-#ifdef G_OS_WIN32
- rtimer->start = GetTickCount ();
-#else /* !G_OS_WIN32 */
- gettimeofday (&rtimer->start, NULL);
-#endif /* !G_OS_WIN32 */
+ GETTIME (rtimer->start);
}
void
rtimer = (GRealTimer*) timer;
rtimer->active = FALSE;
-#ifdef G_OS_WIN32
- rtimer->end = GetTickCount ();
-#else /* !G_OS_WIN32 */
- gettimeofday (&rtimer->end, NULL);
-#endif /* !G_OS_WIN32 */
+ GETTIME(rtimer->end);
}
void
rtimer = (GRealTimer*) timer;
-#ifdef G_OS_WIN32
- rtimer->start = GetTickCount ();
-#else /* !G_OS_WIN32 */
- gettimeofday (&rtimer->start, NULL);
-#endif /* !G_OS_WIN32 */
+ GETTIME (rtimer->start);
}
gdouble
if (rtimer->active)
rtimer->end = GetTickCount ();
- /* Check for wraparound, which happens every 49.7 days.
- * No, Win95 machines probably are never running for that long,
- * but NT machines are.
- */
+ /* Check for wraparound, which happens every 49.7 days. */
if (rtimer->end < rtimer->start)
total = (UINT_MAX - (rtimer->start - rtimer->end)) / 1000.0;
else
if (rtimer->start.tv_usec > rtimer->end.tv_usec)
{
- rtimer->end.tv_usec += G_MICROSEC;
+ rtimer->end.tv_usec += G_USEC_PER_SEC;
rtimer->end.tv_sec--;
}
g_get_current_time (&end_time);
- end_time.tv_sec += microseconds / G_MICROSEC;
- end_time.tv_usec += microseconds % G_MICROSEC;
+ end_time.tv_sec += microseconds / G_USEC_PER_SEC;
+ end_time.tv_usec += microseconds % G_USEC_PER_SEC;
- if (end_time.tv_usec >= G_MICROSEC)
+ if (end_time.tv_usec >= G_USEC_PER_SEC)
{
- end_time.tv_usec -= G_MICROSEC;
+ end_time.tv_usec -= G_USEC_PER_SEC;
end_time.tv_sec += 1;
}
else
{
struct timeval tv;
- tv.tv_sec = microseconds / G_MICROSEC;
- tv.tv_usec = microseconds % G_MICROSEC;
+ tv.tv_sec = microseconds / G_USEC_PER_SEC;
+ tv.tv_usec = microseconds % G_USEC_PER_SEC;
select(0, NULL, NULL, NULL, &tv);
}
#endif