gcancellable: allow g_cancellable_disconnect from "cancelled" handler on same thread
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

MathieuDuponchelle/glib,johne53/MB3Glib,mzabaluev/glib,Distrotech/glib,lukasz-skalski/glib,endlessm/glib,Distrotech/glib,tchakabam/glib,cosimoc/glib,ieei/glib,cosimoc/glib,johne53/MB3Glib,cention-sany/glib,krichter722/glib,endlessm/glib,gale320/glib,ieei/glib,gale320/glib,krichter722/glib,cention-sany/glib,gale320/glib,gale320/glib,cention-sany/glib,lukasz-skalski/glib,ieei/glib,johne53/MB3Glib,johne53/MB3Glib,cention-sany/glib,cosimoc/glib,mzabaluev/glib,tchakabam/glib,johne53/MB3Glib,tamaskenez/glib,lukasz-skalski/glib,cosimoc/glib,johne53/MB3Glib,krichter722/glib,mzabaluev/glib,gale320/glib,MathieuDuponchelle/glib,MathieuDuponchelle/glib,Distrotech/glib,tchakabam/glib,MathieuDuponchelle/glib,MathieuDuponchelle/glib,krichter722/glib,tchakabam/glib,endlessm/glib,ieei/glib,tamaskenez/glib,lukasz-skalski/glib,krichter722/glib,cosimoc/glib,cention-sany/glib,Distrotech/glib,Distrotech/glib,mzabaluev/glib,mzabaluev/glib,endlessm/glib,tamaskenez/glib,endlessm/glib,lukasz-skalski/glib,ieei/glib,tchakabam/glib,tamaskenez/glib,tamaskenez/glib