Index: gdk.h
===================================================================
--- gdk.h	(revision 18106)
+++ gdk.h	(working copy)
@@ -192,6 +192,15 @@
 void     gdk_threads_enter                (void);
 void     gdk_threads_leave                (void);
 void     gdk_threads_init                 (void);
+gboolean gdk_threads_is_locked            (void);
+
+#ifdef G_ENABLE_DEBUG
+#define gdk_threads_check_locked() \
+  g_return_if_fail (gdk_threads_is_locked ())
+#else
+#define gdk_threads_check_locked() 
+#endif
+
 void     gdk_threads_set_lock_functions   (GCallback enter_fn,
 					   GCallback leave_fn);
 
Index: gdk.c
===================================================================
--- gdk.c	(revision 18106)
+++ gdk.c	(working copy)
@@ -381,20 +381,44 @@
   GDK_THREADS_LEAVE ();
 }
 
+#ifdef G_ENABLE_DEBUG
+static GThread *owner = NULL;
+#endif
+
 static void
 gdk_threads_impl_lock (void)
 {
   if (gdk_threads_mutex)
-    g_mutex_lock (gdk_threads_mutex);
+    {
+      g_mutex_lock (gdk_threads_mutex);
+#ifdef G_ENABLE_DEBUG
+      owner = g_thread_self ();
+#endif
+    }
 }
 
 static void
 gdk_threads_impl_unlock (void)
 {
   if (gdk_threads_mutex)
-    g_mutex_unlock (gdk_threads_mutex);
+    {
+#ifdef G_ENABLE_DEBUG
+      owner = NULL;
+#endif
+      g_mutex_unlock (gdk_threads_mutex);
+    }
 }
 
+gboolean
+gdk_threads_is_locked (void)
+{
+#if G_ENABLE_DEBUG
+  if (gdk_threads_mutex)
+    return owner == g_thread_self ();
+#endif
+  return TRUE;
+}
+
 /**
  * gdk_threads_init:
  * 
