From 659fd4113b919a9491c5f872d11a445b6ea48765 Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Tue, 6 Aug 2002 14:50:52 +0000 Subject: [PATCH] Factor out g_main_context_init_pipe from g_main_context_new to initialize 2002-08-06 Sebastian Wilhelmi * 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) --- ChangeLog | 8 ++++ ChangeLog.pre-2-10 | 8 ++++ ChangeLog.pre-2-12 | 8 ++++ ChangeLog.pre-2-2 | 8 ++++ ChangeLog.pre-2-4 | 8 ++++ ChangeLog.pre-2-6 | 8 ++++ ChangeLog.pre-2-8 | 8 ++++ glib/gmain.c | 101 ++++++++++++++++++++++++++++++------------------- gthread/gthread-impl.c | 2 + 9 files changed, 121 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index ecf5b10..a1cc266 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ecf5b10..a1cc266 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ecf5b10..a1cc266 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index ecf5b10..a1cc266 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index ecf5b10..a1cc266 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index ecf5b10..a1cc266 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index ecf5b10..a1cc266 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -9,6 +9,14 @@ thread, because all unbound threads will schedule according to 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 * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/glib/gmain.c b/glib/gmain.c index c9029d1..02e8793 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -219,6 +219,7 @@ static gboolean g_idle_dispatch (GSource *source, G_LOCK_DEFINE_STATIC (main_loop); static GMainContext *default_main_context; +static GSList *main_contexts_without_pipe = NULL; #if defined(G_PLATFORM_WIN32) && defined(__GNUC__) __declspec(dllexport) @@ -567,7 +568,10 @@ g_main_context_unref_and_unlock (GMainContext *context) #else CloseHandle (context->wake_up_semaphore); #endif - } + } + else + main_contexts_without_pipe = g_slist_remove (main_contexts_without_pipe, + context); #endif g_free (context); @@ -590,6 +594,45 @@ g_main_context_unref (GMainContext *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: * @@ -611,47 +654,29 @@ g_main_context_new () context->ref_count = 1; - context->next_id = 1; - - context->source_list = NULL; - + context->next_id = 1; + + context->source_list = NULL; + #if HAVE_POLL - context->poll_func = (GPollFunc)poll; + context->poll_func = (GPollFunc)poll; #else - context->poll_func = g_poll; + context->poll_func = g_poll; #endif - - context->cached_poll_array = NULL; - context->cached_poll_array_size = 0; - - context->pending_dispatches = g_ptr_array_new (); - - context->time_is_current = FALSE; - + + context->cached_poll_array = NULL; + context->cached_poll_array_size = 0; + + context->pending_dispatches = g_ptr_array_new (); + + context->time_is_current = FALSE; + #ifdef G_THREADS_ENABLED - if (g_thread_supported ()) - { -#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; - 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 - } + if (g_thread_supported ()) + g_main_context_init_pipe (context); + else + main_contexts_without_pipe = g_slist_prepend (main_contexts_without_pipe, + context); #endif return context; diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c index 1ea464d..28d97e0 100644 --- a/gthread/gthread-impl.c +++ b/gthread/gthread-impl.c @@ -66,6 +66,7 @@ void g_mutex_init (void); void g_mem_init (void); void g_messages_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))) @@ -381,6 +382,7 @@ g_thread_init (GThreadFunctions* init) g_mem_init (); g_messages_init (); g_convert_init (); + g_main_thread_init (); /* now we can set g_threads_got_initialized and thus enable * all the thread functions -- 2.7.4