kms: Add API to register impl file descriptors

To let the MetaKmsImpl implementation register file descriptor GSource
where the invoke function is ensured to be executed in the impl context.

https://gitlab.gnome.org/GNOME/mutter/issues/548
https://gitlab.gnome.org/GNOME/mutter/merge_requests/525
This commit is contained in:
Jonas Ådahl 2019-03-10 13:48:18 +01:00 committed by Georges Basile Stavracas Neto
parent ca21ca6745
commit 2238c9f180
2 changed files with 79 additions and 0 deletions

View File

@ -45,6 +45,11 @@ GSource * meta_kms_add_source_in_impl (MetaKms *kms,
GSourceFunc func,
gpointer user_data);
GSource * meta_kms_register_fd_in_impl (MetaKms *kms,
int fd,
MetaKmsImplTaskFunc dispatch,
gpointer user_data);
gboolean meta_kms_in_impl_task (MetaKms *kms);
#define meta_assert_in_kms_impl(kms) \

View File

@ -40,6 +40,17 @@ typedef struct _MetaKmsSimpleImplSource
MetaKms *kms;
} MetaKmsSimpleImplSource;
typedef struct _MetaKmsFdImplSource
{
GSource source;
gpointer fd_tag;
MetaKms *kms;
MetaKmsImplTaskFunc dispatch;
gpointer user_data;
} MetaKmsFdImplSource;
struct _MetaKms
{
GObject parent;
@ -165,6 +176,69 @@ meta_kms_add_source_in_impl (MetaKms *kms,
return source;
}
static gboolean
meta_kms_fd_impl_source_check (GSource *source)
{
MetaKmsFdImplSource *fd_impl_source = (MetaKmsFdImplSource *) source;
return g_source_query_unix_fd (source, fd_impl_source->fd_tag) & G_IO_IN;
}
static gboolean
meta_kms_fd_impl_source_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
MetaKmsFdImplSource *fd_impl_source = (MetaKmsFdImplSource *) source;
MetaKms *kms = fd_impl_source->kms;
gboolean ret;
GError *error = NULL;
kms->in_impl_task = TRUE;
ret = fd_impl_source->dispatch (kms->impl,
fd_impl_source->user_data,
&error);
kms->in_impl_task = FALSE;
if (!ret)
{
g_warning ("Failed to dispatch fd source: %s", error->message);
g_error_free (error);
}
return G_SOURCE_CONTINUE;
}
static GSourceFuncs fd_impl_source_funcs = {
NULL,
meta_kms_fd_impl_source_check,
meta_kms_fd_impl_source_dispatch
};
GSource *
meta_kms_register_fd_in_impl (MetaKms *kms,
int fd,
MetaKmsImplTaskFunc dispatch,
gpointer user_data)
{
GSource *source;
MetaKmsFdImplSource *fd_impl_source;
meta_assert_in_kms_impl (kms);
source = g_source_new (&fd_impl_source_funcs, sizeof (MetaKmsFdImplSource));
fd_impl_source = (MetaKmsFdImplSource *) source;
fd_impl_source->dispatch = dispatch;
fd_impl_source->user_data = user_data;
fd_impl_source->kms = kms;
fd_impl_source->fd_tag = g_source_add_unix_fd (source, fd,
G_IO_IN | G_IO_ERR);
g_source_attach (source, g_main_context_get_thread_default ());
return source;
}
gboolean
meta_kms_in_impl_task (MetaKms *kms)
{