[macOS] Do not block raster thread when shutting down (flutter/engine#38777)

This commit is contained in:
Matej Knopp
2023-01-12 22:28:06 +01:00
committed by GitHub
parent 2bff9b8d85
commit 86c5ce8349
2 changed files with 19 additions and 0 deletions

View File

@@ -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)

View File

@@ -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();