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

Commit e9b7a2d

Browse files
authored
[macOS] Do not block raster thread when shutting down (#38777)
1 parent 6880157 commit e9b7a2d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
77

88
#include <functional>
9+
#include <thread>
910

1011
#include "flutter/fml/synchronization/waitable_event.h"
1112
#include "flutter/lib/ui/window/platform_message.h"
@@ -668,6 +669,19 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
668669
}
669670
}
670671

672+
TEST(EngineTest, ThreadSynchronizerNotBlockingRasterThreadAfterShutdown) {
673+
FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init];
674+
[threadSynchronizer shutdown];
675+
676+
std::thread rasterThread([&threadSynchronizer] {
677+
[threadSynchronizer performCommit:CGSizeMake(100, 100)
678+
notify:^{
679+
}];
680+
});
681+
682+
rasterThread.join();
683+
}
684+
671685
} // namespace flutter::testing
672686

673687
// NOLINTEND(clang-analyzer-core.StackAddressEscape)

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

+5
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+
// Engine is shutting down, main thread may be blocked by the engine
84+
// waiting for raster thread to finish.
85+
return;
86+
}
8287
fml::AutoResetWaitableEvent& e = event;
8388
_scheduledBlocks.push_back(^{
8489
notify();

0 commit comments

Comments
 (0)