Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5fae98e

Browse files
committed
[macOS] Do not block raster thread when shutting down
1 parent 6256f05 commit 5fae98e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ - (void)performCommit:(CGSize)size notify:(nonnull dispatch_block_t)notify {
7979
fml::AutoResetWaitableEvent event;
8080
{
8181
std::unique_lock<std::mutex> lock(_mutex);
82+
if (_shuttingDown) {
83+
// FlutterView is shutting down and will not drain schedued blocks
84+
// on main thread anymore.
85+
return;
86+
}
8287
fml::AutoResetWaitableEvent& e = event;
8388
_scheduledBlocks.push_back(^{
8489
notify();

shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
66

77
#import <Metal/Metal.h>
8+
#include <thread>
89

910
#import "flutter/testing/testing.h"
1011

@@ -28,3 +29,16 @@ - (void)viewDidReshape:(nonnull NSView*)view {
2829
reshapeListener:listener];
2930
EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
3031
}
32+
33+
TEST(FlutterView, ThreadSynchronizerNotBlockingRasterThreadAfterShutdown) {
34+
FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init];
35+
[threadSynchronizer shutdown];
36+
37+
std::thread rasterThread([&threadSynchronizer] {
38+
[threadSynchronizer performCommit:CGSizeMake(100, 100)
39+
notify:^{
40+
}];
41+
});
42+
43+
rasterThread.join();
44+
}

0 commit comments

Comments
 (0)