mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-07 19:35:50 +01:00
Factor out g_main_context_init_pipe from g_main_context_new to initialize
2002-08-06 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * glib/gmain.c: Factor out g_main_context_init_pipe from g_main_context_new to initialize the wakeup pipe of a context. Call that function from g_main_context_new if threads are initialized and for all contexts when threads are initialized in g_main_thread_init. (#86872) * gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
This commit is contained in:
parent
3faf95913d
commit
659fd4113b
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
thread, because all unbound threads will schedule according to
|
thread, because all unbound threads will schedule according to
|
||||||
that value and it defaults to 0 (the minimal value).
|
that value and it defaults to 0 (the minimal value).
|
||||||
|
|
||||||
|
* glib/gmain.c: Factor out g_main_context_init_pipe from
|
||||||
|
g_main_context_new to initialize the wakeup pipe of a
|
||||||
|
context. Call that function from g_main_context_new if threads are
|
||||||
|
initialized and for all contexts when threads are initialized
|
||||||
|
in g_main_thread_init. (#86872)
|
||||||
|
|
||||||
|
* gthread/gthread-impl.c: Call g_main_thread_init. (#86872)
|
||||||
|
|
||||||
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
Thu Jul 25 14:23:15 2002 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
* glib/gfileutils.c: Clarify the behavior of g_build_path()
|
||||||
|
101
glib/gmain.c
101
glib/gmain.c
@ -219,6 +219,7 @@ static gboolean g_idle_dispatch (GSource *source,
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
#if defined(G_PLATFORM_WIN32) && defined(__GNUC__)
|
#if defined(G_PLATFORM_WIN32) && defined(__GNUC__)
|
||||||
__declspec(dllexport)
|
__declspec(dllexport)
|
||||||
@ -567,7 +568,10 @@ g_main_context_unref_and_unlock (GMainContext *context)
|
|||||||
#else
|
#else
|
||||||
CloseHandle (context->wake_up_semaphore);
|
CloseHandle (context->wake_up_semaphore);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
main_contexts_without_pipe = g_slist_remove (main_contexts_without_pipe,
|
||||||
|
context);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_free (context);
|
g_free (context);
|
||||||
@ -590,6 +594,45 @@ g_main_context_unref (GMainContext *context)
|
|||||||
g_main_context_unref_and_unlock (context);
|
g_main_context_unref_and_unlock (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef G_THREADS_ENABLED
|
||||||
|
static void
|
||||||
|
g_main_context_init_pipe (GMainContext *context)
|
||||||
|
{
|
||||||
|
# ifndef G_OS_WIN32
|
||||||
|
if (pipe (context->wake_up_pipe) < 0)
|
||||||
|
g_error ("Cannot create pipe main loop wake-up: %s\n",
|
||||||
|
g_strerror (errno));
|
||||||
|
|
||||||
|
context->wake_up_rec.fd = context->wake_up_pipe[0];
|
||||||
|
context->wake_up_rec.events = G_IO_IN;
|
||||||
|
# else
|
||||||
|
context->wake_up_semaphore = CreateSemaphore (NULL, 0, 100, NULL);
|
||||||
|
if (context->wake_up_semaphore == NULL)
|
||||||
|
g_error ("Cannot create wake-up semaphore: %s",
|
||||||
|
g_win32_error_message (GetLastError ()));
|
||||||
|
context->wake_up_rec.fd = (gint) context->wake_up_semaphore;
|
||||||
|
context->wake_up_rec.events = G_IO_IN;
|
||||||
|
# ifdef G_MAIN_POLL_DEBUG
|
||||||
|
g_print ("wake-up semaphore: %#x\n", (guint) context->wake_up_semaphore);
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
g_main_context_add_poll_unlocked (context, 0, &context->wake_up_rec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
g_main_thread_init ()
|
||||||
|
{
|
||||||
|
GSList *curr = main_contexts_without_pipe;
|
||||||
|
while (curr)
|
||||||
|
{
|
||||||
|
g_main_context_init_pipe ((GMainContext *)curr->data);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
g_slist_free (main_contexts_without_pipe);
|
||||||
|
main_contexts_without_pipe = NULL;
|
||||||
|
}
|
||||||
|
#endif /* G_THREADS_ENABLED */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_main_context_new:
|
* g_main_context_new:
|
||||||
*
|
*
|
||||||
@ -611,47 +654,29 @@ g_main_context_new ()
|
|||||||
|
|
||||||
context->ref_count = 1;
|
context->ref_count = 1;
|
||||||
|
|
||||||
context->next_id = 1;
|
context->next_id = 1;
|
||||||
|
|
||||||
context->source_list = NULL;
|
context->source_list = NULL;
|
||||||
|
|
||||||
#if HAVE_POLL
|
#if HAVE_POLL
|
||||||
context->poll_func = (GPollFunc)poll;
|
context->poll_func = (GPollFunc)poll;
|
||||||
#else
|
#else
|
||||||
context->poll_func = g_poll;
|
context->poll_func = g_poll;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
context->cached_poll_array = NULL;
|
context->cached_poll_array = NULL;
|
||||||
context->cached_poll_array_size = 0;
|
context->cached_poll_array_size = 0;
|
||||||
|
|
||||||
context->pending_dispatches = g_ptr_array_new ();
|
context->pending_dispatches = g_ptr_array_new ();
|
||||||
|
|
||||||
context->time_is_current = FALSE;
|
context->time_is_current = FALSE;
|
||||||
|
|
||||||
#ifdef G_THREADS_ENABLED
|
#ifdef G_THREADS_ENABLED
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
{
|
g_main_context_init_pipe (context);
|
||||||
#ifndef G_OS_WIN32
|
else
|
||||||
if (pipe (context->wake_up_pipe) < 0)
|
main_contexts_without_pipe = g_slist_prepend (main_contexts_without_pipe,
|
||||||
g_error ("Cannot create pipe main loop wake-up: %s\n",
|
context);
|
||||||
g_strerror (errno));
|
|
||||||
|
|
||||||
context->wake_up_rec.fd = context->wake_up_pipe[0];
|
|
||||||
context->wake_up_rec.events = G_IO_IN;
|
|
||||||
g_main_context_add_poll_unlocked (context, 0, &context->wake_up_rec);
|
|
||||||
#else
|
|
||||||
context->wake_up_semaphore = CreateSemaphore (NULL, 0, 100, NULL);
|
|
||||||
if (context->wake_up_semaphore == NULL)
|
|
||||||
g_error ("Cannot create wake-up semaphore: %s",
|
|
||||||
g_win32_error_message (GetLastError ()));
|
|
||||||
context->wake_up_rec.fd = (gint) context->wake_up_semaphore;
|
|
||||||
context->wake_up_rec.events = G_IO_IN;
|
|
||||||
#ifdef G_MAIN_POLL_DEBUG
|
|
||||||
g_print ("wake-up semaphore: %#x\n", (guint) context->wake_up_semaphore);
|
|
||||||
#endif
|
|
||||||
g_main_context_add_poll_unlocked (context, 0, &context->wake_up_rec);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
@ -66,6 +66,7 @@ void g_mutex_init (void);
|
|||||||
void g_mem_init (void);
|
void g_mem_init (void);
|
||||||
void g_messages_init (void);
|
void g_messages_init (void);
|
||||||
void g_convert_init (void);
|
void g_convert_init (void);
|
||||||
|
void g_main_thread_init (void);
|
||||||
|
|
||||||
#define G_MUTEX_DEBUG_INFO(mutex) (*((gpointer*)(((char*)mutex)+G_MUTEX_SIZE)))
|
#define G_MUTEX_DEBUG_INFO(mutex) (*((gpointer*)(((char*)mutex)+G_MUTEX_SIZE)))
|
||||||
|
|
||||||
@ -381,6 +382,7 @@ g_thread_init (GThreadFunctions* init)
|
|||||||
g_mem_init ();
|
g_mem_init ();
|
||||||
g_messages_init ();
|
g_messages_init ();
|
||||||
g_convert_init ();
|
g_convert_init ();
|
||||||
|
g_main_thread_init ();
|
||||||
|
|
||||||
/* now we can set g_threads_got_initialized and thus enable
|
/* now we can set g_threads_got_initialized and thus enable
|
||||||
* all the thread functions
|
* all the thread functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user