mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
gsource: allow NULL check and prepare functions
Allow for NULL GSourceFuncs.check() and .prepare(). For prepare() the source will be taken not to be ready and having an infinite timeout. For check() the source will be taken not to be ready. https://bugzilla.gnome.org/show_bug.cgi?id=686853
This commit is contained in:
parent
8f7f7f6c42
commit
6d25e34998
54
glib/gmain.c
54
glib/gmain.c
@ -3045,17 +3045,26 @@ g_main_context_prepare (GMainContext *context,
|
||||
if (!(source->flags & G_SOURCE_READY))
|
||||
{
|
||||
gboolean result;
|
||||
gboolean (*prepare) (GSource *source,
|
||||
gint *timeout);
|
||||
gboolean (* prepare) (GSource *source,
|
||||
gint *timeout);
|
||||
|
||||
prepare = source->source_funcs->prepare;
|
||||
context->in_check_or_prepare++;
|
||||
UNLOCK_CONTEXT (context);
|
||||
prepare = source->source_funcs->prepare;
|
||||
|
||||
result = (*prepare) (source, &source_timeout);
|
||||
if (prepare)
|
||||
{
|
||||
context->in_check_or_prepare++;
|
||||
UNLOCK_CONTEXT (context);
|
||||
|
||||
LOCK_CONTEXT (context);
|
||||
context->in_check_or_prepare--;
|
||||
result = (* prepare) (source, &source_timeout);
|
||||
|
||||
LOCK_CONTEXT (context);
|
||||
context->in_check_or_prepare--;
|
||||
}
|
||||
else
|
||||
{
|
||||
source_timeout = -1;
|
||||
result = FALSE;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
@ -3227,19 +3236,24 @@ g_main_context_check (GMainContext *context,
|
||||
|
||||
if (!(source->flags & G_SOURCE_READY))
|
||||
{
|
||||
gboolean result;
|
||||
gboolean (*check) (GSource *source);
|
||||
gboolean result;
|
||||
gboolean (* check) (GSource *source);
|
||||
|
||||
check = source->source_funcs->check;
|
||||
|
||||
if (check)
|
||||
{
|
||||
context->in_check_or_prepare++;
|
||||
UNLOCK_CONTEXT (context);
|
||||
|
||||
result = (* check) (source);
|
||||
|
||||
LOCK_CONTEXT (context);
|
||||
context->in_check_or_prepare--;
|
||||
}
|
||||
else
|
||||
result = FALSE;
|
||||
|
||||
check = source->source_funcs->check;
|
||||
|
||||
context->in_check_or_prepare++;
|
||||
UNLOCK_CONTEXT (context);
|
||||
|
||||
result = (*check) (source);
|
||||
|
||||
LOCK_CONTEXT (context);
|
||||
context->in_check_or_prepare--;
|
||||
|
||||
if (result)
|
||||
{
|
||||
GSource *ready_source = source;
|
||||
|
@ -86,11 +86,15 @@ typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs;
|
||||
* a @timeout_ value which should be the maximum timeout (in milliseconds)
|
||||
* which should be passed to the poll() call. The actual timeout used will
|
||||
* be -1 if all sources returned -1, or it will be the minimum of all the
|
||||
* @timeout_ values returned which were >= 0.
|
||||
* @timeout_ values returned which were >= 0. Since 2.36 this may
|
||||
* be %NULL, in which case the effect is as if the function always
|
||||
* returns %FALSE with a timeout of -1.
|
||||
* @check: Called after all the file descriptors are polled. The source
|
||||
* should return %TRUE if it is ready to be dispatched. Note that some
|
||||
* time may have passed since the previous prepare function was called,
|
||||
* so the source should be checked again here.
|
||||
* so the source should be checked again here. Since 2.36 this may
|
||||
* be %NULL, in which case the effect is as if the function always
|
||||
* returns %FALSE.
|
||||
* @dispatch: Called to dispatch the event source, after it has returned
|
||||
* %TRUE in either its @prepare or its @check function. The @dispatch
|
||||
* function is passed in a callback function and data. The callback
|
||||
|
Loading…
Reference in New Issue
Block a user