pygobject r952 - in trunk: . glib gobject



Author: paulp
Date: Wed Aug 27 21:37:30 2008
New Revision: 952
URL: http://svn.gnome.org/viewvc/pygobject?rev=952&view=rev

Log:
2008-08-28  Paul Pogonyshev  <pogonyshev gmx net>

	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.


Modified:
   trunk/ChangeLog
   trunk/glib/pyglib.c
   trunk/glib/pyglib.h
   trunk/gobject/gobjectmodule.c

Modified: trunk/glib/pyglib.c
==============================================================================
--- trunk/glib/pyglib.c	(original)
+++ trunk/glib/pyglib.c	Wed Aug 27 21:37:30 2008
@@ -135,13 +135,25 @@
 		    "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_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

Modified: trunk/glib/pyglib.h
==============================================================================
--- trunk/glib/pyglib.h	(original)
+++ trunk/glib/pyglib.h	Wed Aug 27 21:37:30 2008
@@ -28,6 +28,7 @@
 
 G_BEGIN_DECLS
 
+typedef void (*PyGLibThreadsEnabledFunc) (void);
 typedef void (*PyGLibThreadBlockFunc) (void);
 
 void pyglib_init(void);
@@ -35,6 +36,7 @@
 PyGILState_STATE pyglib_gil_state_ensure(void);
 void pyglib_gil_state_release(PyGILState_STATE state);
 int pyglib_enable_threads(void);
+void pyglib_notify_on_enabling_threads(PyGLibThreadsEnabledFunc callback);
 gboolean pyglib_error_check(GError **error);
 gboolean pyglib_gerror_exception_check(GError **error);
 PyObject *pyglib_register_exception_for_domain(gchar *name,

Modified: trunk/gobject/gobjectmodule.c
==============================================================================
--- trunk/gobject/gobjectmodule.c	(original)
+++ trunk/gobject/gobjectmodule.c	Wed Aug 27 21:37:30 2008
@@ -1812,6 +1812,12 @@
     return 0;
 }
 
+static void
+pyg_note_threads_enabled(void)
+{
+    pygobject_api_functions.threads_enabled = TRUE;
+}
+
 static PyObject *
 pyg_signal_accumulator_true_handled(PyObject *unused, PyObject *args)
 {
@@ -2594,5 +2600,8 @@
       /* signal registration recognizes this special accumulator 'constant' */
     _pyg_signal_accumulator_true_handled_func = \
         PyDict_GetItemString(d, "signal_accumulator_true_handled");
+
+    pygobject_api_functions.threads_enabled = pyglib_threads_enabled();
+    pyglib_notify_on_enabling_threads(pyg_note_threads_enabled);
 }
 PYGLIB_MODULE_END



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]