Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 862
    • Issues 862
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 41
    • Merge requests 41
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Merge requests
  • !2746

gio: Add GCancellableChild, a GCancellable with a GCancellable parent

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Marco Trevisan requested to merge 3v1n0/glib:cancellable-child into main Jun 13, 2022
  • Overview 4
  • Commits 4
  • Pipelines 5
  • Changes 11

Many times we need to manage multiple async operations inside an object and each operation may need to be controlled via a different GCancellable's, however this implies keeping track of all of them.

It's instead at times convenient to just create a main object cancellable to control a chain of GCancellable's that depend on it.

As per this introduce a GCancellable subtype that requires a parent GCancellable object that is monitored for cancellation.

As per the way GCancellable's "cancelled" signal is defined we need to disconnect on it outside the actual callback and we use an idle for that. We avoid keeping references in the involved objects so in case the idle functions may just do nothing.


I preferred not to use a GCancellableSource to avoid extra overhead and to have more control on the data, and also to ensure that a child gets cancelled in the same thread of the parent, and at the very same moment.


To avoid having to introduce even more multi-thread complications (I tried hard to use other mutexes, as we already have them in the parent cancellable, unless we decide to share that one for both implementations), I decided that it's better to just throw an idle and forget it in case the cancellable we're connected to and its child are finalized earlier.

Indeed we could track that, without using Weak refs, and just act early in case we want, but it implies much complication that I don't think it's worth.


Indeed all this could be done without adding a new type, but I thought was better not to touch GCancellable itself adding a new_with_parent constructor for example, to avoid increasing its size when not required.

Edited Jun 14, 2022 by Marco Trevisan
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: cancellable-child