summaryrefslogtreecommitdiff
path: root/gio/gcancellable.c
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-10-28 11:44:16 -0700
committerColin Walters <walters@verbum.org>2013-10-29 10:49:48 -0400
commitc8aba61713ec0f674fa0dc986db3b2db3cdd0c41 (patch)
tree0457034e538ded6eab9ba137ffdcd8f1d9c48867 /gio/gcancellable.c
parent61e8e1cd02cc9b9ae8917262ecc17633312b7683 (diff)
downloadglib-c8aba61713ec0f674fa0dc986db3b2db3cdd0c41.tar.gz
GCancellable: drop lock for callback during connect()
Don't hold the lock when calling the user's callback during g_cancellable_connect() for the case that the cancellable has already fired. Taken from a patch by Alex Larsson. Doc updates from Colin Walters. https://bugzilla.gnome.org/show_bug.cgi?id=705395
Diffstat (limited to 'gio/gcancellable.c')
-rw-r--r--gio/gcancellable.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index fc56b87ce..0bbbf4b08 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -535,6 +535,11 @@ g_cancellable_cancel (GCancellable *cancellable)
*
* See #GCancellable::cancelled for details on how to use this.
*
+ * Since GLib 2.40, the lock protecting @cancellable is not held when
+ * @callback is invoked. This lifts a restriction in place for
+ * earlier GLib versions which now makes it easier to write cleanup
+ * code that unconditionally invokes e.g. g_cancellable_cancel().
+ *
* Returns: The id of the signal handler or 0 if @cancellable has already
* been cancelled.
*
@@ -557,6 +562,8 @@ g_cancellable_connect (GCancellable *cancellable,
void (*_callback) (GCancellable *cancellable,
gpointer user_data);
+ g_mutex_unlock (&cancellable_mutex);
+
_callback = (void *)callback;
id = 0;
@@ -571,9 +578,10 @@ g_cancellable_connect (GCancellable *cancellable,
callback, data,
(GClosureNotify) data_destroy_func,
0);
+
+ g_mutex_unlock (&cancellable_mutex);
}
- g_mutex_unlock (&cancellable_mutex);
return id;
}