Add g_main_context_new_with_flags()

This constructor is useful to set options that can't change after
creation.
This commit is contained in:
Vinícius dos Santos Oliveira 2021-04-12 19:16:14 -03:00 committed by Philip Withnall
parent 6fcad9d288
commit 7ba86be594
3 changed files with 40 additions and 0 deletions

View File

@ -841,7 +841,9 @@ G_SOURCE_REMOVE
<SUBSECTION>
GMainContext
GMainContextFlags
g_main_context_new
g_main_context_new_with_flags
g_main_context_ref
g_main_context_unref
g_main_context_default

View File

@ -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;

View File

@ -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