mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-05 00:46:16 +01:00
Add private glib_get_worker_context() API
The first time this is called, this creates a GMainContext * and a thread to run it. Future calls return the same. There are a lot of places that we could use this in GLib.
This commit is contained in:
parent
b6a2f502f2
commit
1facd36d00
@ -113,6 +113,7 @@ uninstall-ms-lib:
|
|||||||
|
|
||||||
libglib_2_0_la_SOURCES = \
|
libglib_2_0_la_SOURCES = \
|
||||||
glib_probes.d \
|
glib_probes.d \
|
||||||
|
glibprivate.h \
|
||||||
garray.c \
|
garray.c \
|
||||||
gasyncqueue.c \
|
gasyncqueue.c \
|
||||||
gatomic.c \
|
gatomic.c \
|
||||||
|
@ -1273,6 +1273,7 @@ g_utf16_to_ucs4
|
|||||||
g_utf16_to_utf8
|
g_utf16_to_utf8
|
||||||
g_unichar_to_utf8
|
g_unichar_to_utf8
|
||||||
g_unichar_validate
|
g_unichar_validate
|
||||||
|
glib_get_worker_context
|
||||||
glib_pgettext
|
glib_pgettext
|
||||||
glib_gettext
|
glib_gettext
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
|
6
glib/glibprivate.h
Normal file
6
glib/glibprivate.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __GLIBPRIVATE_H__
|
||||||
|
#define __GLIBPRIVATE_H__
|
||||||
|
|
||||||
|
GMainContext *glib_get_worker_context (void);
|
||||||
|
|
||||||
|
#endif /* __GLIBPRIVATE_H__ */
|
36
glib/gmain.c
36
glib/gmain.c
@ -98,6 +98,8 @@
|
|||||||
|
|
||||||
#include "gwakeup.h"
|
#include "gwakeup.h"
|
||||||
|
|
||||||
|
#include "glibprivate.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:main
|
* SECTION:main
|
||||||
* @title: The Main Event Loop
|
* @title: The Main Event Loop
|
||||||
@ -378,6 +380,8 @@ static gboolean g_idle_dispatch (GSource *source,
|
|||||||
GSourceFunc callback,
|
GSourceFunc callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
|
static GMainContext *glib_worker_context;
|
||||||
|
|
||||||
G_LOCK_DEFINE_STATIC (main_loop);
|
G_LOCK_DEFINE_STATIC (main_loop);
|
||||||
static GMainContext *default_main_context;
|
static GMainContext *default_main_context;
|
||||||
static GSList *main_contexts_without_pipe = NULL;
|
static GSList *main_contexts_without_pipe = NULL;
|
||||||
@ -4954,3 +4958,35 @@ g_main_context_invoke_full (GMainContext *context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gpointer
|
||||||
|
glib_worker_main (gpointer data)
|
||||||
|
{
|
||||||
|
LOCK_CONTEXT (glib_worker_context);
|
||||||
|
|
||||||
|
while (TRUE)
|
||||||
|
g_main_context_iterate (glib_worker_context, TRUE, TRUE, G_THREAD_SELF);
|
||||||
|
|
||||||
|
return NULL; /* worst GCC warning message ever... */
|
||||||
|
}
|
||||||
|
|
||||||
|
GMainContext *
|
||||||
|
glib_get_worker_context (void)
|
||||||
|
{
|
||||||
|
gsize initialised;
|
||||||
|
|
||||||
|
g_thread_init_glib ();
|
||||||
|
|
||||||
|
if (g_once_init_enter (&initialised))
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
glib_worker_context = g_main_context_new ();
|
||||||
|
if (g_thread_create (glib_worker_main, NULL, FALSE, &error) == NULL)
|
||||||
|
g_error ("Creating GLib worker thread failed: %s\n", error->message);
|
||||||
|
|
||||||
|
g_once_init_leave (&initialised, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return glib_worker_context;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user