gcancellable: allow g_cancellable_disconnect from "cancelled" handler on same thread
authorRay Strode <rstrode@redhat.com>
Tue, 10 Sep 2013 19:32:12 +0000 (15:32 -0400)
committerAlexander Larsson <alexl@redhat.com>
Mon, 23 Sep 2013 07:09:48 +0000 (09:09 +0200)
commit83605e2d0a7b0d39987715cfd046f7b8ef6de94e
treedca92c3fc6b6872bdbc5f6dad2991191c919c760
parent795a36142d447cf8e45668dc999e29612bc4a796
gcancellable: allow g_cancellable_disconnect from "cancelled" handler on same thread

g_cancellable_disconnect will wait until any pending "cancelled"
handlers finish.  This is useful because disconnecting a handler can have the
side-effect of freeing data that the cancelled handler may rely on.
Unfortunately, the code used to enforce this synchronization between
"cancelled" handlers and g_cancellable_disconnect will also cause
deadlock if the cancelled handler itself calls g_cancellable_disconect.

Obviously, if g_cancellable_disconnect is explicitly called by a "cancelled"
handler, then the "cancelled" handler is shouldering the responsibility
of not using any data that may be freed by disconnection.

Also, g_cancellable_disconnect can be called in unexpected places by
lower layers in the code (for instance as a result of g_source_destroy).
In practice, this means it's easy for deadlocks to inadvertently crop
up when using "cancelled" handlers.

For these reasons, it would be good to fix the deadlock.

This commit prevents the deadlock by allowing foregoing synchronization,
if a pending "cancelled" handler is in the same thread as the
g_cancellabale_disconnnect call.

https://bugzilla.gnome.org/show_bug.cgi?id=705395
gio/gcancellable.c