From 8a5ad5c88b3607114234d4e5c9349cb74101d72e Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Sat, 3 Oct 2020 04:13:36 +0300 Subject: [PATCH] memory pools: Remove std::call_once. --- .gitignore | 3 ++- src/oatpp/codegen/ApiClient_define.hpp | 2 +- src/oatpp/core/base/StrBuffer.hpp | 8 ++------ src/oatpp/core/base/memory/Allocator.hpp | 14 +++----------- src/oatpp/core/base/memory/ObjectPool.hpp | 12 ++---------- src/oatpp/core/data/buffer/IOBuffer.hpp | 8 ++------ src/oatpp/core/data/stream/ChunkedBuffer.hpp | 8 ++------ 7 files changed, 14 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 1a29e37e..c4c44ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -46,8 +46,9 @@ srt/build/ test/build/ # Docker - Dockerfile +docker-compose.yaml +docker-compose.yml # VS .vs/ diff --git a/src/oatpp/codegen/ApiClient_define.hpp b/src/oatpp/codegen/ApiClient_define.hpp index d227770b..79ed9507 100644 --- a/src/oatpp/codegen/ApiClient_define.hpp +++ b/src/oatpp/codegen/ApiClient_define.hpp @@ -305,4 +305,4 @@ static void Z_ADD_HEADERS_##NAME(oatpp::web::client::ApiClient::Headers& headers Z_ADD_DEFAULT_HEADERS_##NAME(headers); \ } \ \ -static void Z_ADD_DEFAULT_HEADERS_##NAME(oatpp::web::client::ApiClient::Headers& headers) \ No newline at end of file +static void Z_ADD_DEFAULT_HEADERS_##NAME(oatpp::web::client::ApiClient::Headers& headers) diff --git a/src/oatpp/core/base/StrBuffer.hpp b/src/oatpp/core/base/StrBuffer.hpp index cb3d38c8..ce149054 100644 --- a/src/oatpp/core/base/StrBuffer.hpp +++ b/src/oatpp/core/base/StrBuffer.hpp @@ -40,12 +40,8 @@ private: static constexpr v_buff_size SM_STRING_POOL_ENTRY_SIZE = 256; - static oatpp::base::memory::ThreadDistributedMemoryPool& getSmallStringPool() { - static std::once_flag flag; - static oatpp::base::memory::ThreadDistributedMemoryPool *pool = nullptr; - std::call_once(flag, []() { - pool = new oatpp::base::memory::ThreadDistributedMemoryPool("Small_String_Pool", SM_STRING_POOL_ENTRY_SIZE, 16); - }); + static memory::ThreadDistributedMemoryPool& getSmallStringPool() { + static auto pool = new memory::ThreadDistributedMemoryPool("Small_String_Pool", SM_STRING_POOL_ENTRY_SIZE, 16); return *pool; } diff --git a/src/oatpp/core/base/memory/Allocator.hpp b/src/oatpp/core/base/memory/Allocator.hpp index b8a07718..3b2ae712 100644 --- a/src/oatpp/core/base/memory/Allocator.hpp +++ b/src/oatpp/core/base/memory/Allocator.hpp @@ -66,12 +66,8 @@ public: public: const AllocatorPoolInfo& m_poolInfo; public: - static oatpp::base::memory::ThreadDistributedMemoryPool& getPool(const AllocatorPoolInfo& info){ - static std::once_flag flag; - static oatpp::base::memory::ThreadDistributedMemoryPool *pool = nullptr; - std::call_once(flag, [&]() { - pool = new oatpp::base::memory::ThreadDistributedMemoryPool(info.poolName, sizeof(T), info.poolChunkSize); - }); + static ThreadDistributedMemoryPool& getPool(const AllocatorPoolInfo& info){ + static auto pool = new ThreadDistributedMemoryPool(info.poolName, sizeof(T), info.poolChunkSize); return *pool; } public: @@ -123,11 +119,7 @@ public: static thread_local oatpp::base::memory::MemoryPool pool(info.poolName, sizeof(T), info.poolChunkSize); return pool; #else - static std::once_flag flag; - static oatpp::base::memory::MemoryPool *pool = nullptr; - std::call_once(flag, [&]() { - pool = new oatpp::base::memory::MemoryPool(info.poolName, sizeof(T), info.poolChunkSize); - }); + static auto pool = new MemoryPool(info.poolName, sizeof(T), info.poolChunkSize); return *pool; #endif } diff --git a/src/oatpp/core/base/memory/ObjectPool.hpp b/src/oatpp/core/base/memory/ObjectPool.hpp index 040a1718..41851a2c 100644 --- a/src/oatpp/core/base/memory/ObjectPool.hpp +++ b/src/oatpp/core/base/memory/ObjectPool.hpp @@ -103,11 +103,7 @@ class POOL_NAME { \ public: \ \ static oatpp::base::memory::ThreadDistributedMemoryPool& getPool(){ \ - static std::once_flag flag; \ - static oatpp::base::memory::ThreadDistributedMemoryPool *pool = nullptr; \ - std::call_once(flag, []() { \ - pool = new oatpp::base::memory::ThreadDistributedMemoryPool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ - }); \ + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ return *pool; \ } \ \ @@ -193,11 +189,7 @@ static void operator delete(void* ptr, void* entry) { \ public: \ \ static oatpp::base::memory::MemoryPool& getPool(){ \ - static std::once_flag flag; \ - static oatpp::base::memory::MemoryPool *pool = nullptr; \ - std::call_once(flag, []() { \ - pool = new oatpp::base::memory::MemoryPool(#POOL_NAME"<"#TYPE">", sizeof(TYPE), CHUNK_SIZE); \ - }); \ + 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 c15a50c9..d1f32c07 100644 --- a/src/oatpp/core/data/buffer/IOBuffer.hpp +++ b/src/oatpp/core/data/buffer/IOBuffer.hpp @@ -44,12 +44,8 @@ public: */ static constexpr v_buff_size BUFFER_SIZE = 4096; private: - static oatpp::base::memory::ThreadDistributedMemoryPool& getBufferPool(){ - static std::once_flag flag; - static oatpp::base::memory::ThreadDistributedMemoryPool *pool = nullptr; - std::call_once(flag, []() { - pool = new oatpp::base::memory::ThreadDistributedMemoryPool("IOBuffer_Buffer_Pool", BUFFER_SIZE, 16); - }); + static oatpp::base::memory::ThreadDistributedMemoryPool& getBufferPool() { + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool("IOBuffer_Buffer_Pool", BUFFER_SIZE, 16); return *pool; } private: diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.hpp b/src/oatpp/core/data/stream/ChunkedBuffer.hpp index 5845d86c..c51c0ebb 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.hpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.hpp @@ -51,12 +51,8 @@ public: static const v_buff_size CHUNK_ENTRY_SIZE; static const v_buff_size CHUNK_CHUNK_SIZE; - static oatpp::base::memory::ThreadDistributedMemoryPool& getSegemntPool(){ - static std::once_flag flag; - static oatpp::base::memory::ThreadDistributedMemoryPool *pool = nullptr; - std::call_once(flag, []() { - pool = new oatpp::base::memory::ThreadDistributedMemoryPool(CHUNK_POOL_NAME, CHUNK_ENTRY_SIZE, CHUNK_CHUNK_SIZE); - }); + static oatpp::base::memory::ThreadDistributedMemoryPool& getSegemntPool() { + static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool(CHUNK_POOL_NAME, CHUNK_ENTRY_SIZE, CHUNK_CHUNK_SIZE); return *pool; }