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
Add ability to disable the raster thread merger #20800
Merged
blasten
merged 16 commits into
flutter:master
from
blasten:raster_thread_merger_disable
Aug 29, 2020
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7481a1f
Add ability to disable the raster thread merger
1fa8467
Enable/Disable from shell delegate
e2082ea
nits
015fd9a
Revert unintended change
a5e146d
Remove tests
3d1528c
Typo
0618d8b
format
58b7838
Tests
1cbbfad
Clean up
1799d42
Fix test
f460e8e
Put check back
f40faeb
Keep logic that unmerges thread in rasterizer tear down
67dfab8
Disable/Enable in shell delegate
e6bd933
Feedback & fix bug
9bf4805
Merge remote-tracking branch 'upstream/master' into raster_thread_mer…
a2d425a
nit
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,6 +305,167 @@ TEST(RasterThreadMerger, HandleTaskQueuesAreTheSame) { | |
| thread1.join(); | ||
| } | ||
|
|
||
| TEST(RasterThreadMerger, Enable) { | ||
| fml::MessageLoop* loop1 = nullptr; | ||
| fml::AutoResetWaitableEvent latch1; | ||
| fml::AutoResetWaitableEvent term1; | ||
| std::thread thread1([&loop1, &latch1, &term1]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop1 = &fml::MessageLoop::GetCurrent(); | ||
| latch1.Signal(); | ||
| term1.Wait(); | ||
| }); | ||
|
|
||
| fml::MessageLoop* loop2 = nullptr; | ||
| fml::AutoResetWaitableEvent latch2; | ||
| fml::AutoResetWaitableEvent term2; | ||
| std::thread thread2([&loop2, &latch2, &term2]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop2 = &fml::MessageLoop::GetCurrent(); | ||
| latch2.Signal(); | ||
| term2.Wait(); | ||
| }); | ||
|
|
||
| latch1.Wait(); | ||
| latch2.Wait(); | ||
|
|
||
| fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId(); | ||
| fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId(); | ||
| const auto raster_thread_merger_ = | ||
| fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2); | ||
|
|
||
| raster_thread_merger_->Disable(); | ||
|
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 we add some assert after this line to ensure the raster_thread_merge is truely disabled? So we know
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. |
||
| raster_thread_merger_->MergeWithLease(1); | ||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->Enable(); | ||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->MergeWithLease(1); | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->DecrementLease(); | ||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| term1.Signal(); | ||
| term2.Signal(); | ||
| thread1.join(); | ||
| thread2.join(); | ||
| } | ||
|
|
||
| TEST(RasterThreadMerger, Disable) { | ||
| fml::MessageLoop* loop1 = nullptr; | ||
| fml::AutoResetWaitableEvent latch1; | ||
| fml::AutoResetWaitableEvent term1; | ||
| std::thread thread1([&loop1, &latch1, &term1]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop1 = &fml::MessageLoop::GetCurrent(); | ||
| latch1.Signal(); | ||
| term1.Wait(); | ||
| }); | ||
|
|
||
| fml::MessageLoop* loop2 = nullptr; | ||
| fml::AutoResetWaitableEvent latch2; | ||
| fml::AutoResetWaitableEvent term2; | ||
| std::thread thread2([&loop2, &latch2, &term2]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop2 = &fml::MessageLoop::GetCurrent(); | ||
| latch2.Signal(); | ||
| term2.Wait(); | ||
| }); | ||
|
|
||
| latch1.Wait(); | ||
| latch2.Wait(); | ||
|
|
||
| fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId(); | ||
| fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId(); | ||
| const auto raster_thread_merger_ = | ||
| fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2); | ||
|
|
||
| raster_thread_merger_->Disable(); | ||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->MergeWithLease(1); | ||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->Enable(); | ||
| raster_thread_merger_->MergeWithLease(1); | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->Disable(); | ||
| raster_thread_merger_->UnMergeNow(); | ||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| { | ||
| auto decrement_result = raster_thread_merger_->DecrementLease(); | ||
| ASSERT_EQ(fml::RasterThreadStatus::kRemainsMerged, decrement_result); | ||
| } | ||
|
|
||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->Enable(); | ||
| raster_thread_merger_->UnMergeNow(); | ||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| raster_thread_merger_->MergeWithLease(1); | ||
|
|
||
| ASSERT_TRUE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| { | ||
| auto decrement_result = raster_thread_merger_->DecrementLease(); | ||
| ASSERT_EQ(fml::RasterThreadStatus::kUnmergedNow, decrement_result); | ||
| } | ||
|
|
||
| ASSERT_FALSE(raster_thread_merger_->IsMerged()); | ||
|
|
||
| term1.Signal(); | ||
| term2.Signal(); | ||
| thread1.join(); | ||
| thread2.join(); | ||
| } | ||
|
|
||
| TEST(RasterThreadMerger, IsEnabled) { | ||
| fml::MessageLoop* loop1 = nullptr; | ||
| fml::AutoResetWaitableEvent latch1; | ||
| fml::AutoResetWaitableEvent term1; | ||
| std::thread thread1([&loop1, &latch1, &term1]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop1 = &fml::MessageLoop::GetCurrent(); | ||
| latch1.Signal(); | ||
| term1.Wait(); | ||
| }); | ||
|
|
||
| fml::MessageLoop* loop2 = nullptr; | ||
| fml::AutoResetWaitableEvent latch2; | ||
| fml::AutoResetWaitableEvent term2; | ||
| std::thread thread2([&loop2, &latch2, &term2]() { | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
| loop2 = &fml::MessageLoop::GetCurrent(); | ||
| latch2.Signal(); | ||
| term2.Wait(); | ||
| }); | ||
|
|
||
| latch1.Wait(); | ||
| latch2.Wait(); | ||
|
|
||
| fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId(); | ||
| fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId(); | ||
| const auto raster_thread_merger_ = | ||
| fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2); | ||
| ASSERT_TRUE(raster_thread_merger_->IsEnabled()); | ||
|
|
||
| raster_thread_merger_->Disable(); | ||
| ASSERT_FALSE(raster_thread_merger_->IsEnabled()); | ||
|
|
||
| raster_thread_merger_->Enable(); | ||
| ASSERT_TRUE(raster_thread_merger_->IsEnabled()); | ||
|
|
||
| term1.Signal(); | ||
| term2.Signal(); | ||
| thread1.join(); | ||
| thread2.join(); | ||
| } | ||
|
|
||
| TEST(RasterThreadMerger, RunExpiredTasksWhileFirstTaskMergesThreads) { | ||
| fml::MessageLoop* loop_platform = nullptr; | ||
| fml::AutoResetWaitableEvent latch1; | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.