A thread-safe pool with a limited byte size.
More...
#include <pool.h>
|
| Pool (uint32_t limit_bytes) |
|
std::shared_ptr< T > | Grab () |
|
void | Recycle (std::shared_ptr< T > object) |
|
uint32_t | GetSize () const |
|
template<typename T>
class impeller::Pool< T >
A thread-safe pool with a limited byte size.
- Template Parameters
-
T | The type that the pool will contain. |
Definition at line 17 of file pool.h.
◆ Pool()
Definition at line 19 of file pool.h.
19 : limit_bytes_(limit_bytes) {}
◆ GetSize()
Definition at line 43 of file pool.h.
44 std::scoped_lock lock(mutex_);
◆ Grab()
Definition at line 21 of file pool.h.
22 std::scoped_lock lock(mutex_);
26 std::shared_ptr<T> result = std::move(pool_.back());
28 size_ -= result->GetSize();
◆ Recycle()
Definition at line 32 of file pool.h.
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));
The documentation for this class was generated from the following file: