Skip to content

Commit

Permalink
[macOS] Do not block raster thread when shutting down (#38777)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored Jan 12, 2023
1 parent 6880157 commit e9b7a2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit e9b7a2d

Please sign in to comment.