[macOS] Do not block raster thread when shutting down (flutter/engine#38777)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
|
||||
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
@@ -668,6 +669,19 @@ TEST_F(FlutterEngineTest, ResponseFromBackgroundThread) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EngineTest, ThreadSynchronizerNotBlockingRasterThreadAfterShutdown) {
|
||||
FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init];
|
||||
[threadSynchronizer shutdown];
|
||||
|
||||
std::thread rasterThread([&threadSynchronizer] {
|
||||
[threadSynchronizer performCommit:CGSizeMake(100, 100)
|
||||
notify:^{
|
||||
}];
|
||||
});
|
||||
|
||||
rasterThread.join();
|
||||
}
|
||||
|
||||
} // namespace flutter::testing
|
||||
|
||||
// NOLINTEND(clang-analyzer-core.StackAddressEscape)
|
||||
|
||||
@@ -79,6 +79,11 @@
|
||||
fml::AutoResetWaitableEvent event;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
if (_shuttingDown) {
|
||||
// Engine is shutting down, main thread may be blocked by the engine
|
||||
// waiting for raster thread to finish.
|
||||
return;
|
||||
}
|
||||
fml::AutoResetWaitableEvent& e = event;
|
||||
_scheduledBlocks.push_back(^{
|
||||
notify();
|
||||
|
||||
Reference in New Issue
Block a user