[glib] Added and Moved checks for includes
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Added and Moved checks for includes
- Date: Tue, 9 Nov 2010 01:49:18 +0000 (UTC)
commit 9806040455d6d482db3908f2d56ddfe455bae660
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Tue Nov 9 09:53:12 2010 +0800
Added and Moved checks for includes
Moved checks for G_OS_WIN32 after GLib header includes and added other checks
required for Windows/MSVC builds
glib/gdatetime.c | 10 +++---
glib/gmessages.c | 18 ++++++------
glib/gscanner.c | 8 +++---
glib/gtimer.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 85 insertions(+), 28 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 35ca791..5608a59 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -54,11 +54,6 @@
#include <unistd.h>
#endif
-#ifndef G_OS_WIN32
-#include <sys/time.h>
-#include <time.h>
-#endif /* !G_OS_WIN32 */
-
#include "gdatetime.h"
#include "gatomic.h"
@@ -73,6 +68,11 @@
#include "glibintl.h"
+#ifndef G_OS_WIN32
+#include <sys/time.h>
+#include <time.h>
+#endif /* !G_OS_WIN32 */
+
/**
* SECTION:date-time
* @title: GDateTime
diff --git a/glib/gmessages.c b/glib/gmessages.c
index f9592ba..245e454 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -41,15 +41,6 @@
#include <locale.h>
#include <errno.h>
-#ifdef G_OS_WIN32
-#include <process.h> /* For getpid() */
-#include <io.h>
-# define STRICT /* Strict typing, please */
-# define _WIN32_WINDOWS 0x0401 /* to get IsDebuggerPresent */
-# include <windows.h>
-# undef STRICT
-#endif
-
#include "gmessages.h"
#include "gbacktrace.h"
@@ -63,6 +54,15 @@
#include "gstrfuncs.h"
#include "gstring.h"
+#ifdef G_OS_WIN32
+#include <process.h> /* For getpid() */
+#include <io.h>
+# define STRICT /* Strict typing, please */
+# define _WIN32_WINDOWS 0x0401 /* to get IsDebuggerPresent */
+# include <windows.h>
+# undef STRICT
+#endif
+
/* --- structures --- */
typedef struct _GLogDomain GLogDomain;
diff --git a/glib/gscanner.c b/glib/gscanner.c
index 1234a60..7dc2eb3 100644
--- a/glib/gscanner.c
+++ b/glib/gscanner.c
@@ -42,10 +42,6 @@
#include <unistd.h>
#endif
-#ifdef G_OS_WIN32
-#include <io.h> /* For _read() */
-#endif
-
#include "gscanner.h"
#include "gprintfint.h"
@@ -53,6 +49,10 @@
#include "gstring.h"
#include "gtestutils.h"
+#ifdef G_OS_WIN32
+#include <io.h> /* For _read() */
+#endif
+
/* --- defines --- */
#define to_lower(c) ( \
(guchar) ( \
diff --git a/glib/gtimer.c b/glib/gtimer.c
index 92e3e3c..8716c6d 100644
--- a/glib/gtimer.c
+++ b/glib/gtimer.c
@@ -37,7 +37,9 @@
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
+#endif
#include <time.h>
#ifndef G_OS_WIN32
#include <errno.h>
@@ -52,7 +54,7 @@
#include "gmem.h"
#include "gstrfuncs.h"
#include "gtestutils.h"
-#include "gmain.h"
+#include "gthread.h"
/**
* SECTION: timers
@@ -63,8 +65,19 @@
* that time. This is done somewhat differently on different platforms,
* and can be tricky to get exactly right, so #GTimer provides a
* portable/convenient interface.
+ *
+ * <note><para>
+ * #GTimer uses a higher-quality clock when thread support is available.
+ * Therefore, calling g_thread_init() while timers are running may lead to
+ * unreliable results. It is best to call g_thread_init() before starting any
+ * timers, if you are using threads at all.
+ * </para></note>
**/
+#define G_NSEC_PER_SEC 1000000000
+
+#define GETTIME(v) (v = g_thread_gettime ())
+
/**
* GTimer:
*
@@ -93,7 +106,7 @@ g_timer_new (void)
timer = g_new (GTimer, 1);
timer->active = TRUE;
- timer->start = g_get_monotonic_time ();
+ GETTIME (timer->start);
return timer;
}
@@ -128,7 +141,7 @@ g_timer_start (GTimer *timer)
timer->active = TRUE;
- timer->start = g_get_monotonic_time ();
+ GETTIME (timer->start);
}
/**
@@ -145,7 +158,7 @@ g_timer_stop (GTimer *timer)
timer->active = FALSE;
- timer->end = g_get_monotonic_time ();
+ GETTIME (timer->end);
}
/**
@@ -161,7 +174,7 @@ g_timer_reset (GTimer *timer)
{
g_return_if_fail (timer != NULL);
- timer->start = g_get_monotonic_time ();
+ GETTIME (timer->start);
}
/**
@@ -189,7 +202,7 @@ g_timer_continue (GTimer *timer)
elapsed = timer->end - timer->start;
- timer->start = g_get_monotonic_time ();
+ GETTIME (timer->start);
timer->start -= elapsed;
@@ -219,7 +232,7 @@ g_timer_continue (GTimer *timer)
**/
gdouble
g_timer_elapsed (GTimer *timer,
- gulong *microseconds)
+ gulong *microseconds)
{
gdouble total;
gint64 elapsed;
@@ -227,7 +240,7 @@ g_timer_elapsed (GTimer *timer,
g_return_val_if_fail (timer != NULL, 0);
if (timer->active)
- timer->end = g_get_monotonic_time ();
+ GETTIME (timer->end);
elapsed = timer->end - timer->start;
@@ -244,13 +257,57 @@ g_usleep (gulong microseconds)
{
#ifdef G_OS_WIN32
Sleep (microseconds / 1000);
-#else
+#else /* !G_OS_WIN32 */
+# ifdef HAVE_NANOSLEEP
struct timespec request, remaining;
request.tv_sec = microseconds / G_USEC_PER_SEC;
request.tv_nsec = 1000 * (microseconds % G_USEC_PER_SEC);
while (nanosleep (&request, &remaining) == -1 && errno == EINTR)
request = remaining;
-#endif
+# else /* !HAVE_NANOSLEEP */
+# ifdef HAVE_NSLEEP
+ /* on AIX, nsleep is analogous to nanosleep */
+ struct timespec request, remaining;
+ request.tv_sec = microseconds / G_USEC_PER_SEC;
+ request.tv_nsec = 1000 * (microseconds % G_USEC_PER_SEC);
+ while (nsleep (&request, &remaining) == -1 && errno == EINTR)
+ request = remaining;
+# else /* !HAVE_NSLEEP */
+ if (g_thread_supported ())
+ {
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+ static GCond* cond = NULL;
+ GTimeVal end_time;
+
+ g_get_current_time (&end_time);
+ if (microseconds > G_MAXLONG)
+ {
+ microseconds -= G_MAXLONG;
+ g_time_val_add (&end_time, G_MAXLONG);
+ }
+ g_time_val_add (&end_time, microseconds);
+
+ g_static_mutex_lock (&mutex);
+
+ if (!cond)
+ cond = g_cond_new ();
+
+ while (g_cond_timed_wait (cond, g_static_mutex_get_mutex (&mutex),
+ &end_time))
+ /* do nothing */;
+
+ g_static_mutex_unlock (&mutex);
+ }
+ else
+ {
+ struct timeval tv;
+ tv.tv_sec = microseconds / G_USEC_PER_SEC;
+ tv.tv_usec = microseconds % G_USEC_PER_SEC;
+ select(0, NULL, NULL, NULL, &tv);
+ }
+# endif /* !HAVE_NSLEEP */
+# endif /* !HAVE_NANOSLEEP */
+#endif /* !G_OS_WIN32 */
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]