-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow embedders to schedule a callback on all engine managed threads. #15980
Conversation
cc @dnicoara |
shell/platform/embedder/embedder.h
Outdated
/// @param[in] user_data A baton passed by the engine to the callback. This | ||
/// baton is not interpreted by the engine in any way. | ||
/// | ||
/// @return The flutter export. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to "The result of the call"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -1747,3 +1746,27 @@ FlutterEngineResult FlutterEngineNotifyLowMemoryWarning( | |||
kInternalInconsistency, | |||
"Could not dispatch the low memory notification message."); | |||
} | |||
|
|||
FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question -- I didn't look through the two bugs immediately before reviewing but what's the rationale for posting to all threads and having the user potentially do something conditionally on the type
param in the closure rather than having this take a thread-type and posting only to the specified task runner? Is the use-case such that you want to post on all or none?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see -- so we can provide some guarantee of synchronicity, looks like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use case requires posting to all threads. But, I can see your approach as being viable as well. Posting to specific threads repeatedly is not a use case that we want to handle. This is supposed to be called once very early on in engine lifecycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be warning people not to attempt to do any cross-thread latching in the closures they pass in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
hmm, I just realized you cannot post a callback from a callback. I’ll make that safe and test it before committing this. |
Wondering, would this be sufficient to cover corner cases? Would it be possible for the embedder to call FlutterEnginePostCallbackOnAllNativeThreads before all the threads are created? With respect to worker threads, would it be possible for new worker threads to be spawned at arbitrary points in time? |
No. If you have an engine ref, this is guaranteed to work.
The number of worker threads are constant at this time. If/when this changes, the engine can hold onto the callback till the engine instance is collected. Maybe I should document that the callback may be executed a long time into the future and the embedder should not associate any handles with the baton with the expectation that all callbacks will be made in a timely manner? |
`FlutterEnginePostCallbackOnAllNativeThreads` schedule a callback to be run on all engine managed threads. The engine will attempt to service this callback the next time the message loops for each managed thread is idle. Since the engine manages the entire lifecycle of multiple threads, there is no opportunity for the embedders to finely tune the priorities of threads directly, or, perform other thread specific configuration (for example, setting thread names for tracing). This callback gives embedders a chance to affect such tuning. Fixes b/143774406 Fixes b/148278215 Fixes b/148278931
2260fef
to
68b829d
Compare
I have patched and tested the re-entrancy issue. |
…troying the engine.
The Windows presubmit failure is MSVC "fatal error C1001: An internal error has occurred in the compiler.". Will try to simplify the statement. |
Awesome, thank you for quelling my concerns! |
flutter/engine@c4229bf...ec32966 git log c4229bf..ec32966 --first-parent --oneline 2020-01-28 [email protected] Revert "Always make gpu thread different from platform thread regardless of platform view (#16068)" (flutter/engine#16161) 2020-01-28 [email protected] Roll fuchsia/sdk/core/mac-amd64 from gNitp... to 5fMtM... (flutter/engine#16153) 2020-01-28 [email protected] Revert "Disable setting a library tag handler." (flutter/engine#16157) 2020-01-28 [email protected] Always make gpu thread different from platform thread regardless of platform view (flutter/engine#16068) 2020-01-28 [email protected] Add test to ensure that concurrent message loops have at least one workers. (flutter/engine#16074) 2020-01-28 [email protected] Revert breaking PRs (flutter/engine#16148) 2020-01-28 [email protected] Roll fuchsia/sdk/core/linux-amd64 from 8Ns10... to 2rLoq... (flutter/engine#15971) 2020-01-28 [email protected] Gets the DPI for all awareness mode and older Windows versions (flutter/engine#15951) 2020-01-28 [email protected] Hold a mutex when updating all CanPostTaskToAllNativeThreads::Captures members. (flutter/engine#16085) 2020-01-28 [email protected] Disable setting a library tag handler. (flutter/engine#16086) 2020-01-28 [email protected] Web PargraphStyle TextHeightBehavior integration (flutter/engine#16075) 2020-01-28 [email protected] Fix flake by making thread ID tracking in CanPostTaskToAllNativeThreads thread safe. (flutter/engine#16081) 2020-01-28 [email protected] Remove buggy assertion in EmbedderTest::CanPostTaskToAllNativeThreads. (flutter/engine#16071) 2020-01-27 [email protected] Remove tonic/platform. (flutter/engine#16062) 2020-01-27 [email protected] Allow embedders to schedule a callback on all engine managed threads. (flutter/engine#15980) 2020-01-27 [email protected] Engine/LibTxt/dart:ui impl of TextHeightBehavior (flutter/engine#15087) 2020-01-27 [email protected] Roll src/third_party/skia f1b2b42613cb..9c1d30dd163e (8 commits) (flutter/engine#16060) 2020-01-27 [email protected] Remove stale recipe changelog. (flutter/engine#15985) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
…flutter#15980) `FlutterEnginePostCallbackOnAllNativeThreads` schedule a callback to be run on all engine managed threads. The engine will attempt to service this callback the next time the message loops for each managed thread is idle. Since the engine manages the entire lifecycle of multiple threads, there is no opportunity for the embedders to finely tune the priorities of threads directly, or, perform other thread specific configuration (for example, setting thread names for tracing). This callback gives embedders a chance to affect such tuning. Fixes flutter/flutter#49551 Fixes b/143774406 Fixes b/148278215 Fixes b/148278931
…threads. (flutter#15980)" This reverts commit 3e7a4ca.
FlutterEnginePostCallbackOnAllNativeThreads
schedule a callback to be run onall engine managed threads. The engine will attempt to service this callback the
next time the message loops for each managed thread is idle. Since the engine
manages the entire lifecycle of multiple threads, there is no opportunity for
the embedders to finely tune the priorities of threads directly, or, perform
other thread specific configuration (for example, setting thread names for
tracing). This callback gives embedders a chance to affect such tuning.
Fixes flutter/flutter#49551
Fixes b/143774406
Fixes b/148278215
Fixes b/148278931