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

Commit 0e84f61

Browse files
authored
Use fml::ScopedCleanupClosure instead of DeathRattle. (#51834)
Closes flutter/flutter#146105. Originally when we authored these suites, `ScopedCleanupClosure` disallowed move-semantics, but that was fixed in #45772, so there is no reason to have a copy of these in different tests. /cc @jonahwilliams
1 parent 5f6dec8 commit 0e84f61

File tree

2 files changed

+14
-53
lines changed

2 files changed

+14
-53
lines changed

impeller/renderer/backend/vulkan/descriptor_pool_vk_unittests.cc

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "flutter/testing/testing.h" // IWYU pragma: keep.
6+
#include "fml/closure.h"
67
#include "fml/synchronization/waitable_event.h"
78
#include "impeller/renderer/backend/vulkan/descriptor_pool_vk.h"
89
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
@@ -23,27 +24,6 @@ TEST(DescriptorPoolRecyclerVKTest, GetDescriptorPoolRecyclerCreatesNewPools) {
2324
context->Shutdown();
2425
}
2526

26-
namespace {
27-
28-
// Invokes the provided callback when the destructor is called.
29-
//
30-
// Can be moved, but not copied.
31-
class DeathRattle final {
32-
public:
33-
explicit DeathRattle(std::function<void()> callback)
34-
: callback_(std::move(callback)) {}
35-
36-
DeathRattle(DeathRattle&&) = default;
37-
DeathRattle& operator=(DeathRattle&&) = default;
38-
39-
~DeathRattle() { callback_(); }
40-
41-
private:
42-
std::function<void()> callback_;
43-
};
44-
45-
} // namespace
46-
4727
TEST(DescriptorPoolRecyclerVKTest, ReclaimMakesDescriptorPoolAvailable) {
4828
auto const context = MockVulkanContextBuilder().Build();
4929

@@ -64,10 +44,10 @@ TEST(DescriptorPoolRecyclerVKTest, ReclaimMakesDescriptorPoolAvailable) {
6444
// destroyed. That should give us a non-flaky signal that the pool has been
6545
// reclaimed as well.
6646
auto waiter = fml::AutoResetWaitableEvent();
67-
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
47+
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
6848
{
69-
UniqueResourceVKT<DeathRattle> resource(context->GetResourceManager(),
70-
std::move(rattle));
49+
UniqueResourceVKT<fml::ScopedCleanupClosure> resource(
50+
context->GetResourceManager(), std::move(rattle));
7151
}
7252
waiter.Wait();
7353
}
@@ -98,10 +78,10 @@ TEST(DescriptorPoolRecyclerVKTest, ReclaimDropsDescriptorPoolIfSizeIsExceeded) {
9878
// See note above.
9979
for (auto i = 0u; i < 2; i++) {
10080
auto waiter = fml::AutoResetWaitableEvent();
101-
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
81+
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
10282
{
103-
UniqueResourceVKT<DeathRattle> resource(context->GetResourceManager(),
104-
std::move(rattle));
83+
UniqueResourceVKT<fml::ScopedCleanupClosure> resource(
84+
context->GetResourceManager(), std::move(rattle));
10585
}
10686
waiter.Wait();
10787
}
@@ -126,10 +106,10 @@ TEST(DescriptorPoolRecyclerVKTest, ReclaimDropsDescriptorPoolIfSizeIsExceeded) {
126106

127107
for (auto i = 0u; i < 2; i++) {
128108
auto waiter = fml::AutoResetWaitableEvent();
129-
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
109+
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
130110
{
131-
UniqueResourceVKT<DeathRattle> resource(context->GetResourceManager(),
132-
std::move(rattle));
111+
UniqueResourceVKT<fml::ScopedCleanupClosure> resource(
112+
context->GetResourceManager(), std::move(rattle));
133113
}
134114
waiter.Wait();
135115
}

impeller/renderer/backend/vulkan/resource_manager_vk_unittests.cc

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <functional>
77
#include <memory>
88
#include <utility>
9+
#include "fml/closure.h"
910
#include "fml/synchronization/waitable_event.h"
1011
#include "gtest/gtest.h"
1112
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
@@ -20,39 +21,19 @@ TEST(ResourceManagerVKTest, CreatesANewInstance) {
2021
EXPECT_NE(a, b);
2122
}
2223

23-
namespace {
24-
25-
// Invokes the provided callback when the destructor is called.
26-
//
27-
// Can be moved, but not copied.
28-
class DeathRattle final {
29-
public:
30-
explicit DeathRattle(std::function<void()> callback)
31-
: callback_(std::move(callback)) {}
32-
33-
DeathRattle(DeathRattle&&) = default;
34-
DeathRattle& operator=(DeathRattle&&) = default;
35-
36-
~DeathRattle() { callback_(); }
37-
38-
private:
39-
std::function<void()> callback_;
40-
};
41-
42-
} // namespace
43-
4424
TEST(ResourceManagerVKTest, ReclaimMovesAResourceAndDestroysIt) {
4525
auto const manager = ResourceManagerVK::Create();
4626

4727
auto waiter = fml::AutoResetWaitableEvent();
4828
auto dead = false;
49-
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
29+
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
5030

5131
// Not killed immediately.
5232
EXPECT_FALSE(waiter.IsSignaledForTest());
5333

5434
{
55-
auto resource = UniqueResourceVKT<DeathRattle>(manager, std::move(rattle));
35+
auto resource = UniqueResourceVKT<fml::ScopedCleanupClosure>(
36+
manager, std::move(rattle));
5637
}
5738

5839
waiter.Wait();

0 commit comments

Comments
 (0)