mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 20:35:49 +01:00
GTimeoutSource: simplify
Take advantage of the new default handling of the 'prepare' and 'check' functions. https://bugzilla.gnome.org/show_bug.cgi?id=657729
This commit is contained in:
parent
768574635d
commit
db7d5306cc
50
glib/gmain.c
50
glib/gmain.c
@ -281,7 +281,6 @@ struct _GMainLoop
|
|||||||
struct _GTimeoutSource
|
struct _GTimeoutSource
|
||||||
{
|
{
|
||||||
GSource source;
|
GSource source;
|
||||||
gint64 expiration;
|
|
||||||
guint interval;
|
guint interval;
|
||||||
gboolean seconds;
|
gboolean seconds;
|
||||||
};
|
};
|
||||||
@ -377,9 +376,6 @@ static gboolean g_source_iter_next (GSourceIter *iter,
|
|||||||
GSource **source);
|
GSource **source);
|
||||||
static void g_source_iter_clear (GSourceIter *iter);
|
static void g_source_iter_clear (GSourceIter *iter);
|
||||||
|
|
||||||
static gboolean g_timeout_prepare (GSource *source,
|
|
||||||
gint *timeout);
|
|
||||||
static gboolean g_timeout_check (GSource *source);
|
|
||||||
static gboolean g_timeout_dispatch (GSource *source,
|
static gboolean g_timeout_dispatch (GSource *source,
|
||||||
GSourceFunc callback,
|
GSourceFunc callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
@ -446,8 +442,8 @@ static GSList *main_context_list = NULL;
|
|||||||
|
|
||||||
GSourceFuncs g_timeout_funcs =
|
GSourceFuncs g_timeout_funcs =
|
||||||
{
|
{
|
||||||
g_timeout_prepare,
|
NULL, /* prepare */
|
||||||
g_timeout_check,
|
NULL, /* check */
|
||||||
g_timeout_dispatch,
|
g_timeout_dispatch,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
@ -4132,8 +4128,9 @@ static void
|
|||||||
g_timeout_set_expiration (GTimeoutSource *timeout_source,
|
g_timeout_set_expiration (GTimeoutSource *timeout_source,
|
||||||
gint64 current_time)
|
gint64 current_time)
|
||||||
{
|
{
|
||||||
timeout_source->expiration = current_time +
|
gint64 expiration;
|
||||||
(guint64) timeout_source->interval * 1000;
|
|
||||||
|
expiration = current_time + (guint64) timeout_source->interval * 1000;
|
||||||
|
|
||||||
if (timeout_source->seconds)
|
if (timeout_source->seconds)
|
||||||
{
|
{
|
||||||
@ -4162,42 +4159,17 @@ g_timeout_set_expiration (GTimeoutSource *timeout_source,
|
|||||||
* always only *increase* the expiration time by adding a full
|
* always only *increase* the expiration time by adding a full
|
||||||
* second in the case that the microsecond portion decreases.
|
* second in the case that the microsecond portion decreases.
|
||||||
*/
|
*/
|
||||||
timeout_source->expiration -= timer_perturb;
|
expiration -= timer_perturb;
|
||||||
|
|
||||||
remainder = timeout_source->expiration % 1000000;
|
remainder = expiration % 1000000;
|
||||||
if (remainder >= 1000000/4)
|
if (remainder >= 1000000/4)
|
||||||
timeout_source->expiration += 1000000;
|
expiration += 1000000;
|
||||||
|
|
||||||
timeout_source->expiration -= remainder;
|
expiration -= remainder;
|
||||||
timeout_source->expiration += timer_perturb;
|
expiration += timer_perturb;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
g_timeout_prepare (GSource *source,
|
|
||||||
gint *timeout)
|
|
||||||
{
|
|
||||||
GTimeoutSource *timeout_source = (GTimeoutSource *) source;
|
|
||||||
gint64 now = g_source_get_time (source);
|
|
||||||
|
|
||||||
if (now < timeout_source->expiration)
|
|
||||||
{
|
|
||||||
/* Round up to ensure that we don't try again too early */
|
|
||||||
*timeout = (timeout_source->expiration - now + 999) / 1000;
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*timeout = 0;
|
g_source_set_ready_time ((GSource *) timeout_source, expiration);
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
g_timeout_check (GSource *source)
|
|
||||||
{
|
|
||||||
GTimeoutSource *timeout_source = (GTimeoutSource *) source;
|
|
||||||
gint64 now = g_source_get_time (source);
|
|
||||||
|
|
||||||
return timeout_source->expiration <= now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user