diff --git a/CMakeLists.txt b/CMakeLists.txt index d77fde8..9a0d548 100644 diff --git a/src/oatpp/core/base/StrBuffer.hpp b/src/oatpp/core/base/StrBuffer.hpp index b00513a..465a2bf 100644 --- a/src/oatpp/core/base/StrBuffer.hpp +++ b/src/oatpp/core/base/StrBuffer.hpp @@ -41,8 +41,8 @@ private: static constexpr v_buff_size SM_STRING_POOL_ENTRY_SIZE = 256; static oatpp::base::memory::ThreadDistributedMemoryPool& getSmallStringPool() { - static oatpp::base::memory::ThreadDistributedMemoryPool pool("Small_String_Pool", SM_STRING_POOL_ENTRY_SIZE, 16); - return pool; + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool("Small_String_Pool", SM_STRING_POOL_ENTRY_SIZE, 16); + return *pool; } static v_buff_size getSmStringBaseSize() { diff --git a/src/oatpp/core/base/memory/Allocator.hpp b/src/oatpp/core/base/memory/Allocator.hpp index f0a8e21..37b7943 100644 --- a/src/oatpp/core/base/memory/Allocator.hpp +++ b/src/oatpp/core/base/memory/Allocator.hpp @@ -67,8 +67,8 @@ public: const AllocatorPoolInfo& m_poolInfo; public: static oatpp::base::memory::ThreadDistributedMemoryPool& getPool(const AllocatorPoolInfo& info){ - static oatpp::base::memory::ThreadDistributedMemoryPool pool(info.poolName, sizeof(T), info.poolChunkSize); - return pool; + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool(info.poolName, sizeof(T), info.poolChunkSize); + return *pool; } public: PoolSharedObjectAllocator(const AllocatorPoolInfo& info) @@ -116,11 +116,11 @@ public: public: static oatpp::base::memory::MemoryPool& getPool(const AllocatorPoolInfo& info){ #ifndef OATPP_COMPAT_BUILD_NO_THREAD_LOCAL - static thread_local oatpp::base::memory::MemoryPool pool(info.poolName, sizeof(T), info.poolChunkSize); + static thread_local oatpp::base::memory::MemoryPool* pool = new oatpp::base::memory::MemoryPool(info.poolName, sizeof(T), info.poolChunkSize); #else - static oatpp::base::memory::MemoryPool pool(info.poolName, sizeof(T), info.poolChunkSize); + static auto pool = new oatpp::base::memory::MemoryPool(info.poolName, sizeof(T), info.poolChunkSize); #endif - return pool; + return *pool; } public: ThreadLocalPoolSharedObjectAllocator(const AllocatorPoolInfo& info) diff --git a/src/oatpp/core/base/memory/ObjectPool.hpp b/src/oatpp/core/base/memory/ObjectPool.hpp index 5eb69cb..3bb2e69 100644 --- a/src/oatpp/core/base/memory/ObjectPool.hpp +++ b/src/oatpp/core/base/memory/ObjectPool.hpp @@ -103,8 +103,8 @@ class POOL_NAME { \ public: \ \ static oatpp::base::memory::ThreadDistributedMemoryPool& getPool(){ \ - static oatpp::base::memory::ThreadDistributedMemoryPool pool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ - return pool; \ + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ + return *pool; \ } \ \ }; \ @@ -151,8 +151,8 @@ static void operator delete(void* ptr, void* entry) { \ public: \ \ static oatpp::base::memory::MemoryPool& getPool(){ \ - static thread_local oatpp::base::memory::MemoryPool pool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ - return pool; \ + static thread_local oatpp::base::memory::MemoryPool* pool = new oatpp::base::memory::MemoryPool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ + return *pool; \ } \ \ }; \ @@ -189,8 +189,8 @@ static void operator delete(void* ptr, void* entry) { \ public: \ \ static oatpp::base::memory::MemoryPool& getPool(){ \ - static oatpp::base::memory::MemoryPool pool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ - return pool; \ + static auto pool = new oatpp::base::memory::MemoryPool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ + return *pool; \ } \ \ }; diff --git a/src/oatpp/core/data/buffer/IOBuffer.hpp b/src/oatpp/core/data/buffer/IOBuffer.hpp index 834c813..0bc822a 100644 --- a/src/oatpp/core/data/buffer/IOBuffer.hpp +++ b/src/oatpp/core/data/buffer/IOBuffer.hpp @@ -45,8 +45,8 @@ public: static constexpr v_buff_size BUFFER_SIZE = 4096; private: static oatpp::base::memory::ThreadDistributedMemoryPool& getBufferPool(){ - static oatpp::base::memory::ThreadDistributedMemoryPool pool("IOBuffer_Buffer_Pool", BUFFER_SIZE, 16); - return pool; + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool("IOBuffer_Buffer_Pool", BUFFER_SIZE, 16); + return *pool; } private: void* m_entry; diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.cpp b/src/oatpp/core/data/stream/ChunkedBuffer.cpp index 359bb6c..cde59ff 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.cpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.cpp @@ -37,6 +37,17 @@ const v_buff_size ChunkedBuffer::CHUNK_ENTRY_SIZE = (1 << ChunkedBuffer::CHUNK_ENTRY_SIZE_INDEX_SHIFT); const v_buff_size ChunkedBuffer::CHUNK_CHUNK_SIZE = 32; +oatpp::base::memory::ThreadDistributedMemoryPool& ChunkedBuffer::getSegemntPool() { + static oatpp::base::memory::ThreadDistributedMemoryPool *pool = nullptr; + static std::once_flag flag; + std::call_once(flag, []() { + if (pool == nullptr) { + pool = new oatpp::base::memory::ThreadDistributedMemoryPool(CHUNK_POOL_NAME, CHUNK_ENTRY_SIZE, CHUNK_CHUNK_SIZE); + } + }); + return *pool; +} + ChunkedBuffer::ChunkedBuffer() : m_size(0) , m_chunkPos(0) diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.hpp b/src/oatpp/core/data/stream/ChunkedBuffer.hpp index c9995d6..63000dd 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.hpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.hpp @@ -51,10 +51,7 @@ public: static const v_buff_size CHUNK_ENTRY_SIZE; static const v_buff_size CHUNK_CHUNK_SIZE; - static oatpp::base::memory::ThreadDistributedMemoryPool& getSegemntPool(){ - static oatpp::base::memory::ThreadDistributedMemoryPool pool(CHUNK_POOL_NAME, CHUNK_ENTRY_SIZE, CHUNK_CHUNK_SIZE); - return pool; - } + static oatpp::base::memory::ThreadDistributedMemoryPool& getSegemntPool(); private: