summaryrefslogtreecommitdiff
path: root/gdk/gdk.c
diff options
context:
space:
mode:
authorMichael Meeks <michael@ximian.com>2003-12-08 17:13:13 +0000
committerMichael Meeks <michael@src.gnome.org>2003-12-08 17:13:13 +0000
commitfa3ca01b174f561727c2f3c7e90195d009de983d (patch)
tree9b0528761f7936d883f539240e02ea7122b56a65 /gdk/gdk.c
parent47f63b8cb2ddd82a78137063c1dd5c99ee63eb03 (diff)
downloadgdk-pixbuf-fa3ca01b174f561727c2f3c7e90195d009de983d.tar.gz
Based on a patch by Martin Kretzschmar; #122448
2003-12-02 Michael Meeks <michael@ximian.com> Based on a patch by Martin Kretzschmar; #122448 * gdk/gdk.h: new gdk_threads_lock, gdk_threads_unlock, point to implementation of GDK_THREADS_ENTER / GDK_THREADS_LEAVE. (GDK_THREADS_ENTER, GDK_THREADS_LEAVE): use gdk_threads_[un]lock function pointers. Deprecate the global gdk_threads_mutex variable. * gdk/gdk.c (gdk_threads_impl_lock, gdk_threads_impl_unlock): new, extracted from GTK_THREADS_ENTER/LEAVE macros. (gdk_threads_init): init gtk_threads_[un]lock if not set. (gdk_threads_set_lock_functions): impl. * gdk/gdkglobals.c: add definitions of gdk_threads_[un]lock.
Diffstat (limited to 'gdk/gdk.c')
-rw-r--r--gdk/gdk.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/gdk/gdk.c b/gdk/gdk.c
index a9f2078f7..67faeab40 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -495,6 +495,20 @@ gdk_threads_leave ()
GDK_THREADS_LEAVE ();
}
+static void
+gdk_threads_impl_lock (void)
+{
+ if (gdk_threads_mutex)
+ g_mutex_lock (gdk_threads_mutex);
+}
+
+static void
+gdk_threads_impl_unlock (void)
+{
+ if (gdk_threads_mutex)
+ g_mutex_unlock (gdk_threads_mutex);
+}
+
/**
* gdk_threads_init:
*
@@ -512,6 +526,48 @@ gdk_threads_init ()
g_error ("g_thread_init() must be called before gdk_threads_init()");
gdk_threads_mutex = g_mutex_new ();
+ if (!gdk_threads_lock)
+ gdk_threads_lock = gdk_threads_impl_lock;
+ if (!gdk_threads_unlock)
+ gdk_threads_unlock = gdk_threads_impl_unlock;
+}
+
+/**
+ * gdk_threads_set_lock_functions:
+ * @enter_fn: function called to guard gtk+
+ * @leave_fn: function called to release the guard
+ *
+ * Allows the application to replace the standard method that
+ * GDK uses to protect its data structures. Normally, GDK
+ * creates a single #GMutex that is locked by gdk_threads_enter(),
+ * and released by gdk_threads_leave(); using this function an
+ * application provides, instead, a function @enter_fn that is
+ * called by gdk_threads_enter() and a function @leave_fn that is
+ * called by gdk_threads_leave().
+ *
+ * The functions must provide at least same locking functionality
+ * as the default implementation, but can also do extra application
+ * specific processing.
+ *
+ * As an example, consider an application that has its own recursive
+ * lock that when held, holds the GTK+ lock as well. When GTK+ unlocks
+ * the GTK+ lock when entering a recursive main loop, the application
+ * must temporarily release its lock as well.
+ *
+ * Most threaded GTK+ apps won't need to use this method.
+ *
+ * This method must be called before gdk_threads_init, and cannot
+ * be called multiple times.
+ **/
+void
+gdk_threads_set_lock_functions (GCallback enter_fn,
+ GCallback leave_fn)
+{
+ g_return_if_fail (gdk_threads_lock == NULL &&
+ gdk_threads_unlock == NULL);
+
+ gdk_threads_lock = enter_fn;
+ gdk_threads_unlock = leave_fn;
}
G_CONST_RETURN char *