Skip to content

Commit 7ec747b

Browse files
committed
Hold a mutex when updating all CanPostTaskToAllNativeThreads::Captures members.
This is in the same vein as flutter#16081 but includes holding the mutex when updating all members in the Captures struct instead of just when tracking thread IDs.
1 parent 26fd7d0 commit 7ec747b

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

shell/platform/embedder/tests/embedder_unittests.cc

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,8 +3942,12 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) {
39423942
// Waits the adequate number of callbacks to fire.
39433943
fml::CountDownLatch latch;
39443944

3945+
// This class will be accessed from multiple threads concurrently to track
3946+
// thread specific information that is later checked. All updates to fields
3947+
// in this struct must be made with this mutex acquired.
3948+
3949+
std::mutex captures_mutex;
39453950
// Ensures that the expect number of distinct threads were serviced.
3946-
std::mutex thread_ids_mutex;
39473951
std::set<std::thread::id> thread_ids;
39483952

39493953
size_t platform_threads_count = 0;
@@ -3961,22 +3965,22 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) {
39613965
engine.get(),
39623966
[](FlutterNativeThreadType type, void* baton) {
39633967
auto captures = reinterpret_cast<Captures*>(baton);
3964-
switch (type) {
3965-
case kFlutterNativeThreadTypeRender:
3966-
captures->render_threads_count++;
3967-
break;
3968-
case kFlutterNativeThreadTypeWorker:
3969-
captures->worker_threads_count++;
3970-
break;
3971-
case kFlutterNativeThreadTypeUI:
3972-
captures->ui_threads_count++;
3973-
break;
3974-
case kFlutterNativeThreadTypePlatform:
3975-
captures->platform_threads_count++;
3976-
break;
3977-
}
39783968
{
3979-
std::scoped_lock lock(captures->thread_ids_mutex);
3969+
std::scoped_lock lock(captures->captures_mutex);
3970+
switch (type) {
3971+
case kFlutterNativeThreadTypeRender:
3972+
captures->render_threads_count++;
3973+
break;
3974+
case kFlutterNativeThreadTypeWorker:
3975+
captures->worker_threads_count++;
3976+
break;
3977+
case kFlutterNativeThreadTypeUI:
3978+
captures->ui_threads_count++;
3979+
break;
3980+
case kFlutterNativeThreadTypePlatform:
3981+
captures->platform_threads_count++;
3982+
break;
3983+
}
39803984
captures->thread_ids.insert(std::this_thread::get_id());
39813985
}
39823986
captures->latch.CountDown();

0 commit comments

Comments
 (0)