Skip to content
  • Ray Strode's avatar
    gcancellable: allow g_cancellable_disconnect from "cancelled" handler on same thread · 83605e2d
    Ray Strode authored and Alexander Larsson's avatar Alexander Larsson committed
    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
    83605e2d