From 7ba86be594fe5733c7a3df031d94c1e37765ff88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20dos=20Santos=20Oliveira?= Date: Mon, 12 Apr 2021 19:16:14 -0300 Subject: [PATCH] Add g_main_context_new_with_flags() This constructor is useful to set options that can't change after creation. --- docs/reference/glib/glib-sections.txt | 2 ++ glib/gmain.c | 19 +++++++++++++++++++ glib/gmain.h | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index eff14e1ea..35b58cfb0 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -841,7 +841,9 @@ G_SOURCE_REMOVE GMainContext +GMainContextFlags g_main_context_new +g_main_context_new_with_flags g_main_context_ref g_main_context_unref g_main_context_default diff --git a/glib/gmain.c b/glib/gmain.c index ba8e0b08c..69fca6260 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -270,6 +270,7 @@ struct _GMainContext GCond cond; GThread *owner; guint owner_count; + GMainContextFlags flags; GSList *waiters; gint ref_count; /* (atomic) */ @@ -658,6 +659,23 @@ g_main_context_new_with_next_id (guint next_id) **/ GMainContext * g_main_context_new (void) +{ + return g_main_context_new_with_flags (G_MAIN_CONTEXT_FLAGS_NONE); +} + +/** + * g_main_context_new_with_flags: + * @flags: a bitwise-OR combination of #GMainContextFlags flags that can only be + * set at creation time. + * + * Creates a new #GMainContext structure. + * + * Returns: (transfer full): the new #GMainContext + * + * Since: 2.72 + */ +GMainContext * +g_main_context_new_with_flags (GMainContextFlags flags) { static gsize initialised; GMainContext *context; @@ -681,6 +699,7 @@ g_main_context_new (void) context->sources = g_hash_table_new (NULL, NULL); context->owner = NULL; + context->flags = flags; context->waiters = NULL; context->ref_count = 1; diff --git a/glib/gmain.h b/glib/gmain.h index 8e15f3da4..8e7d77290 100644 --- a/glib/gmain.h +++ b/glib/gmain.h @@ -38,6 +38,21 @@ typedef enum /*< flags >*/ G_IO_NVAL GLIB_SYSDEF_POLLNVAL } GIOCondition; +/** + * GMainContextFlags: + * @G_MAIN_CONTEXT_FLAGS_NONE: Default behaviour. + * + * Flags to pass to g_main_context_new_with_flags() which affect the behaviour + * of a #GMainContext. + * + * Since: 2.72 + */ +GLIB_AVAILABLE_TYPE_IN_2_72 +typedef enum /*< flags >*/ +{ + G_MAIN_CONTEXT_FLAGS_NONE = 0, +} GMainContextFlags; + /** * GMainContext: @@ -358,6 +373,10 @@ struct _GSourceFuncs GLIB_AVAILABLE_IN_ALL GMainContext *g_main_context_new (void); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +GLIB_AVAILABLE_IN_2_72 +GMainContext *g_main_context_new_with_flags (GMainContextFlags flags); +G_GNUC_END_IGNORE_DEPRECATIONS GLIB_AVAILABLE_IN_ALL GMainContext *g_main_context_ref (GMainContext *context); GLIB_AVAILABLE_IN_ALL