summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2003-07-26 12:05:51 +0000
committerJames Henstridge <jamesh@src.gnome.org>2003-07-26 12:05:51 +0000
commitf12b1f2641b24969564a3d991c909cce96ddffd6 (patch)
tree0bbae8afa345731f12d89eff1b172b7ad127d552
parentde951f27c052037e2deeb38864d71037c0817f80 (diff)
downloadpygtk-f12b1f2641b24969564a3d991c909cce96ddffd6.tar.gz
apply Elliot Lee's threading patch. Still need to fix the remaining
2003-07-26 James Henstridge <james@daa.com.au> * gtk/gdk.override: apply Elliot Lee's threading patch. Still need to fix the remaining threading problems.
-rw-r--r--ChangeLog5
-rw-r--r--TODO11
-rw-r--r--gtk/gdk.override47
3 files changed, 33 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d4bdb6b..ae308535 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-07-26 James Henstridge <james@daa.com.au>
+
+ * gtk/gdk.override: apply Elliot Lee's threading patch. Still
+ need to fix the remaining threading problems.
+
2003-07-25 James Henstridge <james@daa.com.au>
* gtk/gtktreeview.override
diff --git a/TODO b/TODO
index b05595e8..bc578301 100644
--- a/TODO
+++ b/TODO
@@ -10,14 +10,3 @@ Things to do for the gtk 2.0 based release
new tree models defined in Python. Need to look at how the
GtkTreeIter->tree_node lifetime is handled, as it doesn't look like
anything is called to let us know that that data should be unrefed.
-
-- Make python subclasses of GObjects into new types in the GType
- system. Should be possible to do from GObject.__class_init__ and a
- bit of extra magic.
-
- Maybe stop adding get_type() class methods, and switch over to
- adding __gtype__ class attributes. This is easier when defining new
- GObject types (ie. just set an attribute), but may mean calling
- get_type() for all classes. Could do some special code so that the
- __gtype__ attributes are of a special type that calls the get_type()
- macro to convert to an int.
diff --git a/gtk/gdk.override b/gtk/gdk.override
index 82022fe6..3a1cf7b5 100644
--- a/gtk/gdk.override
+++ b/gtk/gdk.override
@@ -94,36 +94,46 @@ static GStaticPrivate pythreadstate_key = G_STATIC_PRIVATE_INIT;
static GStaticPrivate lock_count_key = G_STATIC_PRIVATE_INIT;
static PyInterpreterState *pyinterpstate = NULL;
+static gint *
+pygdk_get_lock_count(void)
+{
+ gint *lock_count = g_static_private_get(&lock_count_key);
+
+ if(!lock_count) {
+ lock_count = g_malloc(sizeof(gint));
+ *lock_count = 1;
+ g_static_private_set(&lock_count_key, lock_count, NULL);
+ }
+
+ return lock_count;
+}
+
static void
pygdk_block_threads (void)
{
- gint lock_count = GPOINTER_TO_INT(g_static_private_get(&lock_count_key));
+ PyThreadState *_save;
+ gint *lock_count = pygdk_get_lock_count();
- if (lock_count == 0) {
- PyThreadState *_save;
-
- _save = g_static_private_get(&pythreadstate_key);
- if (_save == NULL) {
- _save = PyThreadState_New(pyinterpstate);
- }
- Py_BLOCK_THREADS;
- }
- lock_count++;
- g_static_private_set(&lock_count_key, GINT_TO_POINTER(lock_count), NULL);
+ (*lock_count)++;
+ if(*lock_count == 1) {
+ _save = g_static_private_get(&pythreadstate_key);
+ g_assert(_save);
+ Py_BLOCK_THREADS;
+ g_static_private_set(&pythreadstate_key, NULL, NULL);
+ }
}
+
static void
pygdk_unblock_threads (void)
{
- gint lock_count = GPOINTER_TO_INT(g_static_private_get(&lock_count_key));
-
- lock_count--;
- if (lock_count == 0) {
- PyThreadState *_save;
+ PyThreadState *_save;
+ gint *lock_count = pygdk_get_lock_count();
+ if(*lock_count == 1) {
Py_UNBLOCK_THREADS;
g_static_private_set(&pythreadstate_key, _save, NULL);
}
- g_static_private_set(&lock_count_key, GINT_TO_POINTER(lock_count), NULL);
+ (*lock_count)--;
}
#endif
@@ -136,7 +146,6 @@ _wrap_gdk_threads_init(PyObject *self)
PyEval_InitThreads();
gdk_threads_init();
- g_static_private_set(&lock_count_key, GINT_TO_POINTER(1), NULL);
pyinterpstate = PyThreadState_Get()->interp;