5 #ifndef FLUTTER_IMPELLER_RENDERER_POOL_H_
6 #define FLUTTER_IMPELLER_RENDERER_POOL_H_
19 explicit Pool(uint32_t limit_bytes) : limit_bytes_(limit_bytes) {}
21 std::shared_ptr<T>
Grab() {
22 std::scoped_lock lock(mutex_);
26 std::shared_ptr<T> result = std::move(pool_.back());
28 size_ -= result->GetSize();
33 std::scoped_lock lock(mutex_);
34 size_t object_size =
object->GetSize();
35 if (size_ + object_size <= limit_bytes_ &&
36 object_size < (limit_bytes_ / 2)) {
39 pool_.emplace_back(std::move(
object));
44 std::scoped_lock lock(mutex_);
49 std::vector<std::shared_ptr<T>> pool_;
50 const uint32_t limit_bytes_;
53 mutable std::mutex mutex_;
A thread-safe pool with a limited byte size.
std::shared_ptr< T > Grab()
Pool(uint32_t limit_bytes)
void Recycle(std::shared_ptr< T > object)
ScopedObject< Object > Create(CtorArgs &&... args)