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

[macOS] Do not block raster thread when shutting down #38777

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -668,6 +669,19 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
}
}

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)
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ - (void)performCommit:(CGSize)size notify:(nonnull dispatch_block_t)notify {
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();
Expand Down