[glib/wip/ghandle: 13/16] Add "coarse" monotonic time
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/ghandle: 13/16] Add "coarse" monotonic time
- Date: Fri, 19 Dec 2014 17:26:24 +0000 (UTC)
commit b9ba498d42b14b381cfb51922218b1b39f6c4a2f
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Dec 18 22:22:04 2014 -0500
Add "coarse" monotonic time
docs/reference/glib/glib-sections.txt | 1 +
glib/gmain.c | 28 ++++++++++++++++++++++++++++
glib/gmain.h | 2 ++
3 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index aaac897..02809af 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1455,6 +1455,7 @@ g_time_val_to_iso8601
<SUBSECTION>
g_get_monotonic_time
+g_get_coarse_monotonic_time
g_get_real_time
<SUBSECTION>
diff --git a/glib/gmain.c b/glib/gmain.c
index 8b369c3..ad505cf 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -2850,6 +2850,34 @@ g_get_monotonic_time (void)
}
#endif
+/**
+ * g_get_coarse_monotonic_time:
+ *
+ * Gets the "coarse" monotonic time.
+ *
+ * This is the same thing as fetching the monotonic time except that it
+ * may be implemented in a way that is faster and less accurate. On
+ * Linux this corresponds to CLOCK_MONOTONIC_COARSE.
+ *
+ * Since: 2.44
+ */
+gint64
+g_get_coarse_monotonic_time (void)
+{
+#ifdef __linux__
+ struct timespec ts;
+
+ result = clock_gettime (CLOCK_MONOTONIC_COARSE, &ts);
+
+ if G_UNLIKELY (result != 0)
+ g_error ("GLib requires CLOCK_MONOTONIC_COARSE on Linux");
+
+ return (((gint64) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
+#else
+ return g_get_monotonic_time ();
+#endif
+}
+
static void
g_main_dispatch_free (gpointer dispatch)
{
diff --git a/glib/gmain.h b/glib/gmain.h
index 55ae364..4d1c320 100644
--- a/glib/gmain.h
+++ b/glib/gmain.h
@@ -543,6 +543,8 @@ GLIB_AVAILABLE_IN_ALL
void g_get_current_time (GTimeVal *result);
GLIB_AVAILABLE_IN_ALL
gint64 g_get_monotonic_time (void);
+GLIB_AVAILABLE_IN_2_44
+gint64 g_get_coarse_monotonic_time (void);
GLIB_AVAILABLE_IN_ALL
gint64 g_get_real_time (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]