From: Ryan Lortie Date: Fri, 22 Oct 2010 16:40:08 +0000 (+0200) Subject: Add g_source_get_time() X-Git-Tag: 2.27.2~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7d8363fbec421d1e3e8b1a198fd7efb2ec9d2bc;p=platform%2Fupstream%2Fglib.git 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(). --- diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index c33912c..c547c8c 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -535,6 +535,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);