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

Commit 3303a3e

Browse files
authored
[Impeller] Hold the CommandPoolVK at a higher scope. (#46013)
Fixes flutter/flutter#134982. I could never reproduce the flakes locally, but this should prevent `pool1 == pool2`.
1 parent 87396c0 commit 3303a3e

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

impeller/renderer/backend/vulkan/command_pool_vk_unittests.cc

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "flutter/testing/testing.h" // IWYU pragma: keep.
66
#include "fml/synchronization/waitable_event.h"
7+
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
78
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
89
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
910

@@ -13,26 +14,28 @@ namespace testing {
1314
TEST(CommandPoolRecyclerVKTest, GetsACommandPoolPerThread) {
1415
auto const context = MockVulkanContextBuilder().Build();
1516

16-
// Record the memory location of each pointer to a command pool.
17-
int* pool1 = nullptr;
18-
int* pool2 = nullptr;
19-
20-
// Create a command pool in two threads and record the memory location.
21-
std::thread thread1([&]() {
22-
auto const pool = context->GetCommandPoolRecycler()->Get();
23-
pool1 = reinterpret_cast<int*>(pool.get());
24-
});
25-
26-
std::thread thread2([&]() {
27-
auto const pool = context->GetCommandPoolRecycler()->Get();
28-
pool2 = reinterpret_cast<int*>(pool.get());
29-
});
30-
31-
thread1.join();
32-
thread2.join();
33-
34-
// The two command pools should be different.
35-
EXPECT_NE(pool1, pool2);
17+
{
18+
// Record the memory location of each pointer to a command pool.
19+
//
20+
// These pools have to be held at this context, otherwise they will be
21+
// dropped and recycled and potentially reused by another thread, causing
22+
// flaky tests.
23+
std::shared_ptr<CommandPoolVK> pool1;
24+
std::shared_ptr<CommandPoolVK> pool2;
25+
26+
// Create a command pool in two threads and record the memory location.
27+
std::thread thread1(
28+
[&]() { pool1 = context->GetCommandPoolRecycler()->Get(); });
29+
30+
std::thread thread2(
31+
[&]() { pool2 = context->GetCommandPoolRecycler()->Get(); });
32+
33+
thread1.join();
34+
thread2.join();
35+
36+
// The two command pools should be different.
37+
EXPECT_NE(pool1, pool2);
38+
}
3639

3740
context->Shutdown();
3841
}

0 commit comments

Comments
 (0)