7 #import "flutter/fml/synchronization/waitable_event.h"
8 #import "flutter/testing/testing.h"
14 - (nullable instancetype)
init;
15 - (void)dispatchMainTask:(nonnull
void (^)())task;
16 - (void)dispatchRenderTask:(nonnull
void (^)())task;
22 dispatch_queue_t _mainQueue;
23 std::shared_ptr<fml::AutoResetWaitableEvent>
_mainLatch;
33 - (nullable instancetype)
init {
36 _mainQueue = dispatch_queue_create(
"MAIN", DISPATCH_QUEUE_SERIAL);
37 _renderQueue = dispatch_queue_create(
"RENDER", DISPATCH_QUEUE_SERIAL);
43 - (void)dispatchMainTask:(nonnull
void (^)())task {
44 dispatch_async(_mainQueue, task);
47 - (void)dispatchRenderTask:(nonnull
void (^)())task {
52 fml::AutoResetWaitableEvent latch;
53 fml::AutoResetWaitableEvent* pLatch = &latch;
54 dispatch_async(_mainQueue, ^{
61 fml::AutoResetWaitableEvent latch;
62 fml::AutoResetWaitableEvent* pLatch = &latch;
71 TEST(FlutterThreadSynchronizerTest, RegularCommit) {
77 __block
int notifiedResize = 0;
86 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
88 EXPECT_EQ(notifiedResize, 1);
98 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
100 EXPECT_EQ(notifiedResize, 2);
103 __block
int notifiedCommit = 0;
111 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
113 EXPECT_EQ(notifiedCommit, 1);
116 TEST(FlutterThreadSynchronizerTest, ResizingBlocksRenderingUntilSizeMatches) {
123 fml::AutoResetWaitableEvent begunResizingLatch;
124 fml::AutoResetWaitableEvent* begunResizing = &begunResizingLatch;
135 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
145 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
152 begunResizing->Signal();
155 begunResizing->Wait();
156 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
166 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
176 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
181 TEST(FlutterThreadSynchronizerTest, ShutdownMakesEverythingNonBlocking) {
185 fml::AutoResetWaitableEvent begunResizingLatch;
186 fml::AutoResetWaitableEvent* begunResizing = &begunResizingLatch;
197 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
207 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
218 begunResizing->Signal();
221 begunResizing->Wait();
222 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
233 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
236 TEST(FlutterThreadSynchronizerTest, RegularCommitForMultipleViews) {
240 fml::AutoResetWaitableEvent begunResizingLatch;
241 fml::AutoResetWaitableEvent* begunResizing = &begunResizingLatch;
254 begunResizing->Signal();
257 begunResizing->Wait();
258 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
266 begunResizing->Signal();
269 begunResizing->Signal();
270 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
285 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
288 TEST(FlutterThreadSynchronizerTest, ResizingForMultipleViews) {
292 fml::AutoResetWaitableEvent begunResizingLatch;
293 fml::AutoResetWaitableEvent* begunResizing = &begunResizingLatch;
309 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
323 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
330 begunResizing->Signal();
333 begunResizing->Wait();
334 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
344 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
354 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
364 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
375 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);