Open Bug 1796566 Opened 3 years ago Updated 1 year ago

Make it easier to use async shutdown blockers from C++

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

People

(Reporter: jstutte, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 obsolete file)

No description provided.

Bug 1709184 gives some hints for what we probably want in terms of thread-safety here:

  • Singletons can be instantiated off-main-thread, thus the used base classes need to be thread safe.
  • If off-main-thread there is potential for races between checking the shutdown phase and actually adding a blocker for it that might lead to problems. We might want to think about an appropriate mutex that prevents us from advancing the shutdown phase when in this state.
  • We might want to have guarantees on which thread our OnInstantiation and OnShutdown callbacks are actually executed. I'd assume that we want to call OnShutdown on the same owning event target on which we called our first OnInstantiation (accounting also for thread pool situations) ?
Attachment #9299772 - Attachment description: WIP: Bug 1796566 - Have a base class for async shutdown managed lazy instantiated singletons. → WIP: Bug 1796566 - Have a base class for async shutdown managed and lazily instantiated singletons.
See Also: → 1760855

Copying over nika's suggestion to not bury it in the patch's comments:

Random idea for an ergonomic wrapper around async shutdown blockers vaguely inspired by the js interface:

    using BlockerFunc = MoveOnlyFunction<RefPtr<GenericPromise>()>;
    using ClearBlockerFunc = std::function<void()>;

    ClearBlockerFunc AddAsyncShutdownBlocker(BlockerFunc aBlocker);

You pass it a closure which returns a GenericPromise which must resolve before advancing shutdown phase, and it returns a function to unregister that closure
We could also have a version which takes a bare RefPtr<GenericPromise> and just waits for it to resolve or reject, then removes it

Attachment #9299772 - Attachment is obsolete: true
Summary: Have a base class for C++ singletons that uses async shutdown blockers → Make it easier to use async shutdown blockers from C++
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: