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:
Sebastian Wilhelmi 2002-08-06 14:50:52 +00:00 committed by Sebastian Wilhelmi
parent 3faf95913d
commit 659fd4113b
9 changed files with 121 additions and 38 deletions

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

@ -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 <otaylor@redhat.com>
* glib/gfileutils.c: Clarify the behavior of g_build_path()

View File

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

View File

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