From 9a25064b00c4c26670d5b220c466b9805d9172ce Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 14 Apr 2020 14:50:37 +1000 Subject: [PATCH] memorypool: placed mutex around get and release functions Makes all memory pool derivatives effectively thread-safe. --- app/common/memorypool.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/common/memorypool.h b/app/common/memorypool.h index 7b2105f0b..a6abe7aed 100644 --- a/app/common/memorypool.h +++ b/app/common/memorypool.h @@ -23,10 +23,9 @@ #include #include +#include #include -#include - #include "common/define.h" OLIVE_NAMESPACE_ENTER @@ -39,7 +38,7 @@ public: data_ = nullptr; } - ~MemoryPool() { + virtual ~MemoryPool() { delete [] data_; } @@ -67,6 +66,8 @@ public: } void Destroy() { + // FIXME: Invalidate elements sent out here? + delete [] data_; data_ = nullptr; @@ -127,6 +128,8 @@ public: using ElementPtr = std::shared_ptr; ElementPtr Get() { + QMutexLocker locker(&lock_); + for (int i=0;i(e->data()) - reinterpret_cast(data_); int index = diff / GetElementSize(); @@ -158,6 +162,8 @@ private: QVector available_; + QMutex lock_; + }; OLIVE_NAMESPACE_EXIT