[glib: 9/26] gmain: Swap implementations of g_get_current_time() + g_get_real_time()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 9/26] gmain: Swap implementations of g_get_current_time() + g_get_real_time()
- Date: Mon, 29 Jul 2019 13:01:03 +0000 (UTC)
commit fe760ba442f79cc2e8e78612fd3a02d01832a7cb
Author: Philip Withnall <withnall endlessm com>
Date: Tue Jun 18 12:40:22 2019 +0100
gmain: Swap implementations of g_get_current_time() + g_get_real_time()
The former is now deprecated, so it makes sense to base its
implementation on the latter, rather than the other way around.
This introduces no functional changes.
Signed-off-by: Philip Withnall <withnall endlessm com>
Helps: #1438
glib/gmain.c | 52 +++++++++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 27 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 2b95631d0..2bfab29b8 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -2639,34 +2639,14 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
void
g_get_current_time (GTimeVal *result)
{
-#ifndef G_OS_WIN32
- struct timeval r;
-
- g_return_if_fail (result != NULL);
-
- /*this is required on alpha, there the timeval structs are int's
- not longs and a cast only would fail horribly*/
- gettimeofday (&r, NULL);
- result->tv_sec = r.tv_sec;
- result->tv_usec = r.tv_usec;
-#else
- FILETIME ft;
- guint64 time64;
+ gint64 tv;
g_return_if_fail (result != NULL);
- GetSystemTimeAsFileTime (&ft);
- memmove (&time64, &ft, sizeof (FILETIME));
+ tv = g_get_real_time ();
- /* Convert from 100s of nanoseconds since 1601-01-01
- * to Unix epoch. Yes, this is Y2038 unsafe.
- */
- time64 -= G_GINT64_CONSTANT (116444736000000000);
- time64 /= 10;
-
- result->tv_sec = time64 / 1000000;
- result->tv_usec = time64 % 1000000;
-#endif
+ result->tv_sec = tv / 1000000;
+ result->tv_usec = tv % 1000000;
}
G_GNUC_END_IGNORE_DEPRECATIONS
@@ -2690,11 +2670,29 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gint64
g_get_real_time (void)
{
- GTimeVal tv;
+#ifndef G_OS_WIN32
+ struct timeval r;
- g_get_current_time (&tv);
+ /* this is required on alpha, there the timeval structs are ints
+ * not longs and a cast only would fail horribly */
+ gettimeofday (&r, NULL);
- return (((gint64) tv.tv_sec) * 1000000) + tv.tv_usec;
+ return (((gint64) r.tv_sec) * 1000000) + r.tv_usec;
+#else
+ FILETIME ft;
+ guint64 time64;
+
+ GetSystemTimeAsFileTime (&ft);
+ memmove (&time64, &ft, sizeof (FILETIME));
+
+ /* Convert from 100s of nanoseconds since 1601-01-01
+ * to Unix epoch. Yes, this is Y2038 unsafe.
+ */
+ time64 -= G_GINT64_CONSTANT (116444736000000000);
+ time64 /= 10;
+
+ return time64;
+#endif
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]