gstreamer/pygtk.diff

132 lines
4 KiB
Diff
Raw Normal View History

Index: gtk/gdk.override
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/gtk/gdk.override,v
retrieving revision 1.24
diff -u -r1.24 gdk.override
--- gtk/gdk.override 24 Aug 2002 14:25:23 -0000 1.24
+++ gtk/gdk.override 7 Nov 2002 07:26:25 -0000
@@ -55,37 +55,96 @@
* particularly appealing.
*/
#ifdef ENABLE_PYGTK_THREADING
+//#define LDBG
+#define LCNT
+//#define BMTX
static GStaticPrivate pythreadstate_key = G_STATIC_PRIVATE_INIT;
-static GStaticPrivate counter_key = G_STATIC_PRIVATE_INIT;
-#define INITIAL_LOCK_COUNT 1
+static GStaticPrivate lock_count_key = G_STATIC_PRIVATE_INIT;
+static PyInterpreterState *pyinterpstate = NULL;
+#ifdef BMTX
+static GStaticMutex foo = G_STATIC_MUTEX_INIT;
+#endif
static void
pygdk_block_threads (void)
{
- gint counter = GPOINTER_TO_INT(g_static_private_get(&counter_key));
+ gint lock_count = GPOINTER_TO_INT(g_static_private_get(&lock_count_key));
+#ifdef BMTX
+ g_static_mutex_lock(&foo);
+#endif
- if (counter == INITIAL_LOCK_COUNT) {
- PyThreadState *_save;
+#ifdef LDBG
+ fprintf(stderr, "->b (%p) c %d\n", g_thread_self(), lock_count);
+#endif
+#ifdef LCNT
+ if (lock_count == 0) {
+#else
+ {
+#endif
+ PyThreadState *_save;
_save = g_static_private_get(&pythreadstate_key);
+#ifdef LDBG
+ fprintf(stderr, "->b ->t (%p) (ts:%p) c %d\n", g_thread_self(), _save, lock_count);
+#endif
+ if (_save == NULL) {
+#ifdef LDBG
+ fprintf(stderr, "->b ->t _save == NULL (%p) c %d\n", g_thread_self(), lock_count);
+#endif
+ _save = PyThreadState_New(pyinterpstate);
+#ifdef LDBG
+ fprintf(stderr, "->b ->t (%p) (new ts:%p) c %d\n", g_thread_self(), _save, lock_count);
+#endif
+ }
Py_BLOCK_THREADS;
+#ifdef LDBG
+ fprintf(stderr, "->b <-t (%p) c %d\n", g_thread_self(), lock_count);
+#endif
}
- counter--;
- g_static_private_set(&counter_key, GINT_TO_POINTER(counter), NULL);
+ lock_count++;
+ g_static_private_set(&lock_count_key, GINT_TO_POINTER(lock_count), NULL);
+#ifdef LDBG
+ fprintf(stderr, "<-b (%p) c %d\n", g_thread_self(), lock_count);
+#endif
+#ifdef BMTX
+ g_static_mutex_unlock(&foo);
+#endif
}
static void
pygdk_unblock_threads (void)
{
- gint counter = GPOINTER_TO_INT(g_static_private_get(&counter_key));
+ gint lock_count = GPOINTER_TO_INT(g_static_private_get(&lock_count_key));
+#ifdef BMTX
+ g_static_mutex_lock(&foo);
+#endif
- counter++;
- if (counter == INITIAL_LOCK_COUNT) {
- PyThreadState *_save;
+#ifdef LDBG
+ fprintf(stderr, "->u (%p) c %d\n", g_thread_self(), lock_count);
+#endif
+ lock_count--;
+#ifdef LCNT
+ if (lock_count == 0) {
+#else
+ {
+#endif
+ PyThreadState *_save;
+#ifdef LDBG
+ fprintf(stderr, "->u ->t (%p) (ts:%p) c %d\n", g_thread_self(), g_static_private_get(&pythreadstate_key), lock_count);
+#endif
Py_UNBLOCK_THREADS;
+#ifdef LDBG
+ fprintf(stderr, "->u <-t (%p) (s:%p) (ts:%p) c %d\n", g_thread_self(), _save, g_static_private_get(&pythreadstate_key), lock_count);
+#endif
g_static_private_set(&pythreadstate_key, _save, NULL);
}
- g_static_private_set(&counter_key, GINT_TO_POINTER(counter), NULL);
+ g_static_private_set(&lock_count_key, GINT_TO_POINTER(lock_count), NULL);
+#ifdef LDBG
+ fprintf(stderr, "<-u (%p) c %d\n", g_thread_self(), lock_count);
+#endif
+#ifdef BMTX
+ g_static_mutex_unlock(&foo);
+#endif
}
#endif
@@ -96,7 +155,14 @@
/* register gdk thread block/unblock routines with gobjectmodule */
pyg_set_thread_block_funcs (pygdk_block_threads, pygdk_unblock_threads);
+ PyEval_InitThreads();
gdk_threads_init();
+ g_static_private_set(&lock_count_key, GINT_TO_POINTER(1), NULL);
+
+#ifdef LDBG
+ fprintf(stderr, "%s:%s:%d thread state (%p)\n", __FILE__,__FUNCTION__,__LINE__, PyThreadState_Get());
+#endif
+ pyinterpstate = PyThreadState_Get()->interp;
Py_INCREF(Py_None);
return Py_None;