From aaa00ca61016f4ced7bbdf0e363eccbd30a0e4f3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 3 Oct 2021 11:50:40 +0100 Subject: [PATCH] Added pool_ext & generic_pool_ext --- .gitignore | 1 + include/etl/generic_pool.h | 26 ++++++++++++++++++-------- include/etl/pool.h | 23 +++++++++++++++++++---- test/vs2019/etl.vcxproj | 1 + test/vs2019/etl.vcxproj.filters | 3 +++ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 72c021e0..da3224a9 100644 --- a/.gitignore +++ b/.gitignore @@ -325,3 +325,4 @@ test/vs2019/Test2 test/vs2019/Debug MSVC - Force C++03 test/vs2019/Debug LLVM - No STL test/vs2019/Debug - No STL +test/build-make diff --git a/include/etl/generic_pool.h b/include/etl/generic_pool.h index bda98e74..cd4a6f97 100644 --- a/include/etl/generic_pool.h +++ b/include/etl/generic_pool.h @@ -190,15 +190,22 @@ namespace etl static ETL_CONSTANT uint32_t Element_Size = sizeof(Element); // Should not be copied. - generic_pool(const generic_pool&); - generic_pool& operator =(const generic_pool&); + generic_pool(const generic_pool&) ETL_DELETE; + generic_pool& operator =(const generic_pool&) ETL_DELETE; }; + //************************************************************************* + /// A templated abstract pool implementation that uses a fixed size pool. + /// The storage for the pool is supplied externally. + ///\ingroup pool + //************************************************************************* template - class generic_pool_ext : public etl::ipool { + class generic_pool_ext : public etl::ipool + { private: // The pool element. - union element_internal { + union element_internal + { char* next; ///< Pointer to the next free element. char value[VTypeSize]; ///< Storage for value type. typename etl::type_with_alignment::type dummy; ///< Dummy item to get correct alignment. @@ -210,12 +217,15 @@ namespace etl static ETL_CONSTANT size_t ALIGNMENT = VAlignment; static ETL_CONSTANT size_t TYPE_SIZE = VTypeSize; - using element = typename etl::aligned_storage::value>::type; + typedef typename etl::aligned_storage::value>::type element; //************************************************************************* /// Constructor //************************************************************************* - generic_pool_ext(element* buffer, size_t size) : etl::ipool(reinterpret_cast(&buffer[0]), ELEMENT_INTERNAL_SIZE, size) {} + generic_pool_ext(element* buffer, size_t size) + : etl::ipool(reinterpret_cast(&buffer[0]), ELEMENT_INTERNAL_SIZE, size) + { + } //************************************************************************* /// Allocate an object from the pool. @@ -325,8 +335,8 @@ namespace etl private: // Should not be copied. - generic_pool_ext(const generic_pool_ext&); - generic_pool_ext& operator=(const generic_pool_ext&); + generic_pool_ext(const generic_pool_ext&) ETL_DELETE; + generic_pool_ext& operator=(const generic_pool_ext&) ETL_DELETE; }; } diff --git a/include/etl/pool.h b/include/etl/pool.h index a8a867a0..8d5f5a1a 100644 --- a/include/etl/pool.h +++ b/include/etl/pool.h @@ -179,8 +179,14 @@ namespace etl pool& operator =(const pool&) ETL_DELETE; }; + //************************************************************************* + /// A templated pool implementation that uses a fixed size pool. + /// The storage for the pool is supplied externally. + ///\ingroup pool + //************************************************************************* template - class pool_ext : public etl::generic_pool_ext::value> { + class pool_ext : public etl::generic_pool_ext::value> + { private: typedef etl::generic_pool_ext::value> base_t; @@ -191,7 +197,10 @@ namespace etl //************************************************************************* /// Constructor //************************************************************************* - pool_ext(typename base_t::element* buffer, size_t size) : base_t(buffer, size) {} + pool_ext(typename base_t::element* buffer, size_t size) + : base_t(buffer, size) + { + } //************************************************************************* /// Allocate an object from the pool. @@ -200,7 +209,10 @@ namespace etl /// etl::pool_no_allocation if thrown, otherwise a null pointer is returned. /// Static asserts if the specified type is too large for the pool. //************************************************************************* - T* allocate() { return base_t::template allocate(); } + T* allocate() + { + return base_t::template allocate(); + } #if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT //************************************************************************* @@ -208,7 +220,10 @@ namespace etl /// If asserts or exceptions are enabled and there are no more free items an /// etl::pool_no_allocation if thrown, otherwise a null pointer is returned. //************************************************************************* - T* create() { return base_t::template create(); } + T* create() + { + return base_t::template create(); + } //************************************************************************* /// Allocate storage for an object from the pool and create with 1 parameter. diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 89e16065..fa1202df 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -8276,6 +8276,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 120b521b..4acb0b3f 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -3017,6 +3017,9 @@ Source Files + + Source Files +