7 #include "flutter/fml/cpu_affinity.h"
8 #include "flutter/fml/thread.h"
9 #include "flutter/fml/trace_event.h"
10 #include "fml/logging.h"
23 ResourceManagerVK::ResourceManagerVK() : waiter_([&]() { Start(); }) {}
26 FML_DCHECK(waiter_.get_id() != std::this_thread::get_id())
27 <<
"The ResourceManager being destructed on its own spawned thread is a "
28 <<
"sign that ContextVK was not properly destroyed. A usual fix for this "
29 <<
"is to ensure that ContextVK is shutdown (i.e. context->Shutdown()) "
30 "before the ResourceManager is destroyed (i.e. at the end of a test).";
35 void ResourceManagerVK::Start() {
41 fml::Thread::SetCurrentThreadName(
42 fml::Thread::ThreadConfig{
"io.flutter.impeller.resource_manager"});
45 fml::RequestAffinity(fml::CpuAffinity::kEfficiency);
47 bool should_exit =
false;
48 while (!should_exit) {
49 std::unique_lock lock(reclaimables_mutex_);
53 reclaimables_cv_.wait(
54 lock, [&]() {
return !reclaimables_.empty() || should_exit_; });
58 Reclaimables resources_to_collect;
59 std::swap(resources_to_collect, reclaimables_);
62 should_exit = should_exit_;
69 TRACE_EVENT0(
"Impeller",
"ReclaimResources");
70 resources_to_collect.clear();
81 std::scoped_lock lock(reclaimables_mutex_);
82 reclaimables_.emplace_back(std::move(resource));
84 reclaimables_cv_.notify_one();
87 void ResourceManagerVK::Terminate() {
89 FML_DCHECK(!should_exit_);
92 std::scoped_lock lock(reclaimables_mutex_);
95 reclaimables_cv_.notify_one();