This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Replace Pipeline's ProduceToFront with ProduceIfEmpty to handle thread merging.
#17122
Merged
cyanglaz
merged 5 commits into
flutter:master
from
cyanglaz:pipeline_produce_to_front_if_empty
Mar 20, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,16 +111,22 @@ class Pipeline : public fml::RefCountedThreadSafe<Pipeline<R>> { | |
| GetNextPipelineTraceID()}; // trace id | ||
| } | ||
|
|
||
| // Pushes task to the front of the pipeline. | ||
| // | ||
| // If we exceed the depth completing this continuation, we drop the | ||
| // last frame to preserve the depth of the pipeline. | ||
| // | ||
| // Note: Use |Pipeline::Produce| where possible. This should only be | ||
| // used to en-queue high-priority resources. | ||
| ProducerContinuation ProduceToFront() { | ||
| // Create a `ProducerContinuation` that will only push the task if the queue | ||
| // is empty. | ||
| // Prefer using |Produce|. ProducerContinuation returned by this method | ||
| // doesn't guarantee that the frame will be rendered. | ||
| ProducerContinuation ProduceIfEmpty() { | ||
| if (!empty_.TryWait()) { | ||
| return {}; | ||
| } | ||
| ++inflight_; | ||
| FML_TRACE_COUNTER("flutter", "Pipeline Depth", | ||
| reinterpret_cast<int64_t>(this), // | ||
| "frames in flight", inflight_.load() // | ||
| ); | ||
|
|
||
| return ProducerContinuation{ | ||
| std::bind(&Pipeline::ProducerCommitFront, this, std::placeholders::_1, | ||
| std::bind(&Pipeline::ProducerCommitIfEmpty, this, std::placeholders::_1, | ||
| std::placeholders::_2), // continuation | ||
| GetNextPipelineTraceID()}; // trace id | ||
| } | ||
|
|
@@ -181,13 +187,16 @@ class Pipeline : public fml::RefCountedThreadSafe<Pipeline<R>> { | |
| available_.Signal(); | ||
| } | ||
|
|
||
| void ProducerCommitFront(ResourcePtr resource, size_t trace_id) { | ||
| void ProducerCommitIfEmpty(ResourcePtr resource, size_t trace_id) { | ||
| { | ||
| std::scoped_lock lock(queue_mutex_); | ||
| queue_.emplace_front(std::move(resource), trace_id); | ||
| while (queue_.size() > depth_) { | ||
| queue_.pop_back(); | ||
| if (!queue_.empty()) { | ||
| // Bail if the queue is not empty, opens up spaces to produce other | ||
| // frames. | ||
| empty_.Signal(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a note here describing why this semaphore needs to be signaled?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| return; | ||
| } | ||
| queue_.emplace_back(std::move(resource), trace_id); | ||
| } | ||
|
|
||
| // Ensure the queue mutex is not held as that would be a pessimization. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be useful to add a brief description for the recommended usage of this method. Something along the lines of:
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