7#include "flutter/fml/cpu_affinity.h"
8#include "flutter/fml/thread.h"
9#include "flutter/fml/trace_event.h"
23ResourceManagerVK::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).";
35void ResourceManagerVK::Start() {
46 bool should_exit =
false;
47 while (!should_exit) {
48 std::unique_lock lock(reclaimables_mutex_);
52 reclaimables_cv_.wait(
53 lock, [&]() {
return !reclaimables_.empty() || should_exit_; });
57 Reclaimables resources_to_collect;
58 std::swap(resources_to_collect, reclaimables_);
61 should_exit = should_exit_;
69 resources_to_collect.clear();
80 std::scoped_lock lock(reclaimables_mutex_);
81 reclaimables_.emplace_back(std::move(
resource));
83 reclaimables_cv_.notify_one();
86void ResourceManagerVK::Terminate() {
91 std::scoped_lock lock(reclaimables_mutex_);
94 reclaimables_cv_.notify_one();
static SkString resource(SkPDFResourceType type, int index)
void swap(sk_sp< T > &a, sk_sp< T > &b)
static void SetCurrentThreadName(const ThreadConfig &config)
A resource manager controls how resources are allocated and reclaimed.
static std::shared_ptr< ResourceManagerVK > Create()
Creates a shared resource manager (a dedicated thread).
void Reclaim(std::unique_ptr< ResourceVK > resource)
Mark a resource as being reclaimable.
~ResourceManagerVK()
Destroys the resource manager.
#define FML_DCHECK(condition)
@ kEfficiency
Request CPU affinity for the efficiency cores.
bool RequestAffinity(CpuAffinity affinity)
Request the given affinity for the current thread.
The ThreadConfig is the thread info include thread name, thread priority.
#define TRACE_EVENT0(category_group, name)