[glib/wip/monotonic: 5/9] Add g_source_get_time()
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/monotonic: 5/9] Add g_source_get_time()
- Date: Fri, 22 Oct 2010 17:27:03 +0000 (UTC)
commit 27d751a6e326a0fe25fcea94bd9faa62df3c9b9d
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Oct 22 18:40:08 2010 +0200
Add g_source_get_time()
Cached version of g_get_monotonic_time() that does similar to what
g_source_get_current_time() does for g_get_current_time().
docs/reference/glib/glib-sections.txt | 1 +
glib/glib.symbols | 1 +
glib/gmain.c | 47 ++++++++++++++++++++++++++++++++-
glib/gmain.h | 2 +
4 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index c43ad07..d09d8fe 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -533,6 +533,7 @@ GSourceFunc
g_source_set_callback_indirect
g_source_add_poll
g_source_remove_poll
+g_source_get_time
g_source_get_current_time
g_source_remove
g_source_remove_by_funcs_user_data
diff --git a/glib/glib.symbols b/glib/glib.symbols
index f9ae895..c499549 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -725,6 +725,7 @@ g_source_attach
g_source_destroy
g_source_get_can_recurse
g_source_get_context
+g_source_get_time
g_source_get_current_time
g_source_get_id
g_source_get_name
diff --git a/glib/gmain.c b/glib/gmain.c
index c9bd702..1428059 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -264,6 +264,8 @@ struct _GMainContext
GPollFunc poll_func;
+ GTimeSpec time;
+ gboolean time_is_fresh;
GTimeVal current_time;
gboolean current_time_is_fresh;
};
@@ -608,6 +610,7 @@ g_main_context_new (void)
context->pending_dispatches = g_ptr_array_new ();
+ context->time_is_fresh = FALSE;
context->current_time_is_fresh = FALSE;
#ifdef G_THREADS_ENABLED
@@ -2474,6 +2477,7 @@ g_main_context_prepare (GMainContext *context,
LOCK_CONTEXT (context);
+ context->time_is_fresh = FALSE;
context->current_time_is_fresh = FALSE;
if (context->in_check_or_prepare)
@@ -2638,7 +2642,10 @@ g_main_context_query (GMainContext *context,
{
*timeout = context->timeout;
if (*timeout != 0)
- context->current_time_is_fresh = FALSE;
+ {
+ context->time_is_fresh = FALSE;
+ context->current_time_is_fresh = FALSE;
+ }
}
UNLOCK_CONTEXT (context);
@@ -3386,6 +3393,44 @@ g_source_get_current_time (GSource *source,
}
/**
+ * g_source_get_time:
+ * @source: a #GSource
+ * @timespec: #GTimeSpec structure in which to store the time
+ *
+ * Gets the time to be used when checking this source. The advantage of
+ * calling this function over calling g_get_monotonic_time() directly is
+ * that when checking multiple sources, GLib can cache a single value
+ * instead of having to repeatedly get the system monotonic time.
+ *
+ * The time here is the system monotonic time, if available, or some
+ * other reasonable alternative otherwise. See g_get_monotonic_time().
+ *
+ * Since: 2.28
+ **/
+void
+g_source_get_time (GSource *source,
+ GTimeSpec *timespec)
+{
+ GMainContext *context;
+
+ g_return_if_fail (source->context != NULL);
+
+ context = source->context;
+
+ LOCK_CONTEXT (context);
+
+ if (!context->time_is_fresh)
+ {
+ g_get_monotonic_time (&context->time);
+ context->time_is_fresh = TRUE;
+ }
+
+ *timespec = context->time;
+
+ UNLOCK_CONTEXT (context);
+}
+
+/**
* g_main_context_set_poll_func:
* @context: a #GMainContext
* @func: the function to call to poll all file descriptors
diff --git a/glib/gmain.h b/glib/gmain.h
index eab20e7..e166f44 100644
--- a/glib/gmain.h
+++ b/glib/gmain.h
@@ -365,6 +365,8 @@ void g_source_remove_poll (GSource *source,
void g_source_get_current_time (GSource *source,
GTimeVal *timeval);
+void g_source_get_time (GSource *source,
+ GTimeSpec *timespec);
/* void g_source_connect_closure (GSource *source,
GClosure *closure);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]