From 328b8849ee7e8db2cb02c710a2fadaaac20d0da3 Mon Sep 17 00:00:00 2001 From: Paul Pogonyshev Date: Wed, 27 Aug 2008 21:37:30 +0000 Subject: Bug 547633 – cannot create new threads when pygtk is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-08-28 Paul Pogonyshev Bug 547633 – cannot create new threads when pygtk is used * glib/pyglib.c (pyglib_notify_on_enabling_threads): New function. (pyglib_enable_threads): Invoke all callbacks added with new pyglib_notify_on_enabling_threads(). * gobject/gobjectmodule.c (pyg_note_threads_enabled): New function (callback for new pyglib_notify_on_enabling_threads()). (PYGLIB_MODULE_START): Initialize 'pygobject_api_functions.threads_enabled' and also watch for thread being enabled later on. svn path=/trunk/; revision=952 --- glib/pyglib.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'glib/pyglib.c') diff --git a/glib/pyglib.c b/glib/pyglib.c index 2bb0d7b..4d8ea8b 100644 --- a/glib/pyglib.c +++ b/glib/pyglib.c @@ -135,13 +135,25 @@ pyglib_enable_threads(void) "pyglib threading disabled at compile time"); return FALSE; } + +void +pyglib_notify_on_enabling_threads(PyGLibThreadsEnabledFunc callback) +{ + /* Ignore, threads cannot be enabled. */ +} + #else + +static GSList *thread_enabling_callbacks = NULL; + /* Enable threading; note that the GIL must be held by the current * thread when this function is called */ gboolean pyglib_enable_threads(void) { + GSList *callback; + g_return_val_if_fail (_PyGLib_API != NULL, FALSE); if (_PyGLib_API->threads_enabled) @@ -153,9 +165,20 @@ pyglib_enable_threads(void) _PyGLib_API->threads_enabled = TRUE; pyglib_thread_state_tls_key = PyThread_create_key(); - + + for (callback = thread_enabling_callbacks; callback; callback = callback->next) + ((PyGLibThreadsEnabledFunc) callback->data) (); + + g_slist_free(thread_enabling_callbacks); return TRUE; } + +void +pyglib_notify_on_enabling_threads(PyGLibThreadsEnabledFunc callback) +{ + if (callback && !pyglib_threads_enabled()) + thread_enabling_callbacks = g_slist_append(thread_enabling_callbacks, callback); +} #endif int -- cgit