From 0cbaa1ccc6b2d97fa31595b49878d61f7afa9329 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 15 Apr 2024 00:55:35 +0300 Subject: [PATCH] BufferPool docs + fix --- src/util/BufferPool.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/BufferPool.h b/src/util/BufferPool.h index 36b27517..c441c385 100644 --- a/src/util/BufferPool.h +++ b/src/util/BufferPool.h @@ -9,6 +9,8 @@ #include namespace util { + /// @brief Thread-safe pool of same-sized buffers + /// @tparam T array type template class BufferPool { std::vector> buffers; @@ -19,6 +21,8 @@ namespace util { BufferPool(size_t bufferSize) : bufferSize(bufferSize) { } + /// @brief Retrieve a buffer for use + /// @return pointer that brings buffer back to the pool when destroyed std::shared_ptr get() { std::lock_guard lock(mutex); if (freeBuffers.empty()) { @@ -28,6 +32,7 @@ namespace util { auto* buffer = freeBuffers.front(); freeBuffers.pop(); return std::shared_ptr(buffer, [this](T* ptr) { + std::lock_guard lock(mutex); freeBuffers.push(ptr); }); }