From 8085f97e5225a57d37da5bc0e53fb21f2a322fe1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 24 Apr 2018 14:15:30 +0100 Subject: [PATCH] Rewrite of debug count so that it does not exists in unit test code or when explicitly enabled. --- include/etl/debug_count.h | 60 +++++++------------ include/etl/deque.h | 56 +++++++++--------- include/etl/flat_map.h | 24 ++++---- include/etl/flat_multimap.h | 20 +++---- include/etl/flat_multiset.h | 18 +++--- include/etl/flat_set.h | 22 +++---- include/etl/forward_list.h | 30 +++++----- include/etl/list.h | 38 ++++++------- include/etl/map.h | 6 +- include/etl/memory_model.h | 46 +++++++++++++++ include/etl/multimap.h | 6 +- include/etl/multiset.h | 6 +- include/etl/private/vector_base.h | 4 +- include/etl/queue.h | 16 +++--- include/etl/set.h | 6 +- include/etl/stack.h | 14 ++--- include/etl/unordered_map.h | 16 +++--- include/etl/unordered_multimap.h | 14 ++--- include/etl/unordered_multiset.h | 14 ++--- include/etl/unordered_set.h | 14 ++--- include/etl/vector.h | 95 ++++++++----------------------- test/etl_profile.h | 1 + test/test_queue_mpmc_mutex.cpp | 38 ++++++++++++- test/vs2017/etl.vcxproj | 1 + test/vs2017/etl.vcxproj.filters | 3 + 25 files changed, 293 insertions(+), 275 deletions(-) create mode 100644 include/etl/memory_model.h diff --git a/include/etl/debug_count.h b/include/etl/debug_count.h index 41370c40..3aeede54 100644 --- a/include/etl/debug_count.h +++ b/include/etl/debug_count.h @@ -39,6 +39,15 @@ SOFTWARE. ///\defgroup debug_count debug count ///\ingroup utilities +#if defined(ETL_DEBUG_COUNT) + +#define ETL_DECLARE_DEBUG_COUNT etl::debug_count etl_debug_count +#define ETL_INCREMENT_DEBUG_COUNT ++etl_debug_count +#define ETL_DECREMENT_DEBUG_COUNT --etl_debug_count +#define ETL_ADD_DEBUG_COUNT(n) etl_debug_count += (n) +#define ETL_SUBTRACT_DEBUG_COUNT(n) etl_debug_count -= (n) +#define ETL_RESET_DEBUG_COUNT etl_debug_count.clear() + namespace etl { //*************************************************************************** @@ -51,8 +60,7 @@ namespace etl class debug_count { public: - -#if defined(ETL_DEBUG) + inline debug_count() : count(0) { @@ -113,46 +121,16 @@ namespace etl private: int32_t count; -#else - inline debug_count() - { - } - - inline ~debug_count() - { - } - - inline debug_count& operator ++() - { - return *this; - } - - inline debug_count& operator --() - { - return *this; - } - - inline debug_count& operator +=(int32_t /*n*/) - { - return *this; - } - - inline debug_count& operator -=(int32_t /*n*/) - { - return *this; - } - - inline operator int32_t() - { - return 0; - } - - inline void clear() - { - } - -#endif }; + +#else +#define ETL_DECLARE_DEBUG_COUNT +#define ETL_INCREMENT_DEBUG_COUNT +#define ETL_DECREMENT_DEBUG_COUNT +#define ETL_ADD_DEBUG_COUNT(n) +#define ETL_SUBTRACT_DEBUG_COUNT(n) +#define ETL_RESET_DEBUG_COUNT +#endif // ETL_DEBUG_COUNT } #endif diff --git a/include/etl/deque.h b/include/etl/deque.h index 3a10a4e3..08228ddc 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -211,10 +211,10 @@ namespace etl { } - size_type current_size; ///< The current number of elements in the deque. - const size_type CAPACITY; ///< The maximum number of elements in the deque. - const size_type BUFFER_SIZE; ///< The number of elements in the buffer. - etl::debug_count construct_count; ///< Internal debugging. + size_type current_size; ///< The current number of elements in the deque. + const size_type CAPACITY; ///< The maximum number of elements in the deque. + const size_type BUFFER_SIZE; ///< The number of elements in the buffer. + ETL_DECLARE_DEBUG_COUNT; ///< Internal debugging. }; //*************************************************************************** @@ -935,7 +935,7 @@ namespace etl --_begin; p = etl::addressof(*_begin); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _begin; } else if (insert_position == end()) @@ -943,7 +943,7 @@ namespace etl p = etl::addressof(*_end); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _end - 1; } else @@ -1000,7 +1000,7 @@ namespace etl --_begin; p = etl::addressof(*_begin); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _begin; } else if (insert_position == end()) @@ -1008,7 +1008,7 @@ namespace etl p = etl::addressof(*_end); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _end - 1; } else @@ -1065,7 +1065,7 @@ namespace etl --_begin; p = etl::addressof(*_begin); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _begin; } else if (insert_position == end()) @@ -1073,7 +1073,7 @@ namespace etl p = etl::addressof(*_end); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _end - 1; } else @@ -1130,7 +1130,7 @@ namespace etl --_begin; p = etl::addressof(*_begin); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _begin; } else if (insert_position == end()) @@ -1138,7 +1138,7 @@ namespace etl p = etl::addressof(*_end); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; position = _end - 1; } else @@ -1538,7 +1538,7 @@ namespace etl ::new (&(*_end)) T(value1); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1555,7 +1555,7 @@ namespace etl ::new (&(*_end)) T(value1, value2); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1572,7 +1572,7 @@ namespace etl ::new (&(*_end)) T(value1, value2, value3); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1589,7 +1589,7 @@ namespace etl ::new (&(*_end)) T(value1, value2, value3, value4); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1645,7 +1645,7 @@ namespace etl --_begin; ::new (&(*_begin)) T(value1); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1662,7 +1662,7 @@ namespace etl --_begin; ::new (&(*_begin)) T(value1, value2); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1679,7 +1679,7 @@ namespace etl --_begin; ::new (&(*_begin)) T(value1, value2, value3); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1696,7 +1696,7 @@ namespace etl --_begin; ::new (&(*_begin)) T(value1, value2, value3, value4); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -1811,7 +1811,7 @@ namespace etl if ETL_IF_CONSTEXPR(etl::is_trivially_destructible::value) { current_size = 0; - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; } else { @@ -1850,7 +1850,7 @@ namespace etl --_begin; ::new (&(*_begin)) T(); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -1882,7 +1882,7 @@ namespace etl ::new (&(*item++)) T(*from); ++from; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } while (n-- != 0); } @@ -1894,7 +1894,7 @@ namespace etl ::new (&(*_end)) T(); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -1905,7 +1905,7 @@ namespace etl --_begin; ::new (&(*_begin)) T(value); ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -1916,7 +1916,7 @@ namespace etl ::new (&(*_end)) T(value); ++_end; ++current_size; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -1926,7 +1926,7 @@ namespace etl { (*_begin).~T(); --current_size; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; ++_begin; } @@ -1938,7 +1938,7 @@ namespace etl --_end; (*_end).~T(); --current_size; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //************************************************************************* diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 087b792c..2c7e2f99 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -234,7 +234,7 @@ namespace etl { value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; std::pair result = refmap_t::insert_at(i_element, *pvalue); i_element->second = result.first->second; @@ -306,7 +306,7 @@ namespace etl value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); } @@ -367,7 +367,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (i_element->first != key))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); } else @@ -399,7 +399,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (i_element->first != key))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); } else @@ -431,7 +431,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (i_element->first != key))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); } else @@ -463,7 +463,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (i_element->first != key))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); } else @@ -495,7 +495,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (i_element->first != key))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); } else @@ -525,7 +525,7 @@ namespace etl i_element->~value_type(); storage.release(etl::addressof(*i_element)); refmap_t::erase(i_element); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; return 1; } } @@ -539,7 +539,7 @@ namespace etl i_element->~value_type(); storage.release(etl::addressof(*i_element)); refmap_t::erase(i_element); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //********************************************************************* @@ -558,7 +558,7 @@ namespace etl itr->~value_type(); storage.release(etl::addressof(*itr)); ++itr; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } refmap_t::erase(first, last); @@ -585,7 +585,7 @@ namespace etl } } - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; refmap_t::clear(); } @@ -765,7 +765,7 @@ namespace etl storage_t& storage; /// Internal debugging. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index 4611f8af..210664ff 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -260,7 +260,7 @@ namespace etl value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refmap_t::insert_at(i_element, *pvalue); return result; @@ -313,7 +313,7 @@ namespace etl ::new ((void*)etl::addressof(pvalue->first)) key_type(key); ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value); iterator i_element = lower_bound(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return refmap_t::insert_at(i_element, *pvalue); } @@ -331,7 +331,7 @@ namespace etl ::new ((void*)etl::addressof(pvalue->first)) key_type(key); ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1); iterator i_element = lower_bound(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return refmap_t::insert_at(i_element, *pvalue); } @@ -349,7 +349,7 @@ namespace etl ::new ((void*)etl::addressof(pvalue->first)) key_type(key); ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1, value2); iterator i_element = lower_bound(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return refmap_t::insert_at(i_element, *pvalue); } @@ -367,7 +367,7 @@ namespace etl ::new ((void*)etl::addressof(pvalue->first)) key_type(key); ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1, value2, value3); iterator i_element = lower_bound(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return refmap_t::insert_at(i_element, *pvalue); } @@ -385,7 +385,7 @@ namespace etl ::new ((void*)etl::addressof(pvalue->first)) key_type(key); ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value1, value2, value3, value4); iterator i_element = lower_bound(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return refmap_t::insert_at(i_element, *pvalue); } @@ -420,7 +420,7 @@ namespace etl i_element->~value_type(); storage.release(etl::addressof(*i_element)); refmap_t::erase(i_element); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //********************************************************************* @@ -439,7 +439,7 @@ namespace etl itr->~value_type(); storage.release(etl::addressof(*itr)); ++itr; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } refmap_t::erase(first, last); @@ -466,7 +466,7 @@ namespace etl } } - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; refmap_t::clear(); } @@ -646,7 +646,7 @@ namespace etl storage_t& storage; /// Internal debugging. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 243c9ddb..442f2f99 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -236,7 +236,7 @@ namespace etl value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refset_t::insert_at(i_element, *pvalue); return result; @@ -292,7 +292,7 @@ namespace etl iterator i_element = lower_bound(*pvalue); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return std::pair(refset_t::insert_at(i_element, *pvalue)); } @@ -310,7 +310,7 @@ namespace etl iterator i_element = lower_bound(*pvalue); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return std::pair(refset_t::insert_at(i_element, *pvalue)); } @@ -328,7 +328,7 @@ namespace etl iterator i_element = lower_bound(*pvalue); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return std::pair(refset_t::insert_at(i_element, *pvalue)); } @@ -346,7 +346,7 @@ namespace etl iterator i_element = lower_bound(*pvalue); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return std::pair(refset_t::insert_at(i_element, *pvalue)); } @@ -380,7 +380,7 @@ namespace etl etl::destroy_at(etl::addressof(*i_element)); storage.release(etl::addressof(*i_element)); refset_t::erase(i_element); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //********************************************************************* @@ -399,7 +399,7 @@ namespace etl etl::destroy_at(etl::addressof(*itr)); storage.release(etl::addressof(*itr)); ++itr; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } refset_t::erase(first, last); @@ -426,7 +426,7 @@ namespace etl } } - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; refset_t::clear(); } @@ -606,7 +606,7 @@ namespace etl storage_t& storage; /// Internal debugging. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index c2f0f4c2..fe7590d6 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -239,7 +239,7 @@ namespace etl value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refset_t::insert_at(i_element, *pvalue); } @@ -300,7 +300,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (*i_element != *pvalue))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refset_t::insert_at(i_element, *pvalue); } else @@ -333,7 +333,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (*i_element != *pvalue))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refset_t::insert_at(i_element, *pvalue); } else @@ -366,7 +366,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (*i_element != *pvalue))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refset_t::insert_at(i_element, *pvalue); } else @@ -399,7 +399,7 @@ namespace etl // Doesn't already exist? if ((i_element == end() || (*i_element != *pvalue))) { - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; result = refset_t::insert_at(i_element, *pvalue); } else @@ -431,7 +431,7 @@ namespace etl etl::destroy_at(etl::addressof(*i_element)); storage.release(etl::addressof(*i_element)); refset_t::erase(i_element); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; return 1; } } @@ -445,7 +445,7 @@ namespace etl etl::destroy_at(etl::addressof(*i_element)); storage.release(etl::addressof(*i_element)); refset_t::erase(i_element); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //********************************************************************* @@ -464,7 +464,7 @@ namespace etl etl::destroy_at(etl::addressof(*itr)); storage.release(etl::addressof(*itr)); ++itr; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } refset_t::erase(first, last); @@ -488,11 +488,11 @@ namespace etl etl::destroy_at(etl::addressof(*itr)); storage.release(etl::addressof(*itr)); ++itr; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } } - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; refset_t::clear(); } @@ -672,7 +672,7 @@ namespace etl storage_t& storage; /// Internal debugging. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 0d32dfe5..6249e0ba 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -275,10 +275,10 @@ namespace etl left->next = right; } - node_t start_node; ///< The node that acts as the forward_list start. - etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. - const size_type MAX_SIZE; ///< The maximum size of the forward_list. - etl::debug_count construct_count; ///< Internal debugging. + node_t start_node; ///< The node that acts as the forward_list start. + etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. + const size_type MAX_SIZE; ///< The maximum size of the forward_list. + ETL_DECLARE_DEBUG_COUNT; ///< Internal debugging. }; //*************************************************************************** @@ -658,7 +658,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(start_node, *p_data_node); } @@ -673,7 +673,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(start_node, *p_data_node); } @@ -688,7 +688,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(start_node, *p_data_node); } @@ -703,7 +703,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3, value4); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(start_node, *p_data_node); } @@ -793,7 +793,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -809,7 +809,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -825,7 +825,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -841,7 +841,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3, value4); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node_after(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -1247,7 +1247,7 @@ namespace etl if ETL_IF_CONSTEXPR(etl::is_trivially_destructible::value) { p_node_pool->release_all(); - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; } else { @@ -1326,7 +1326,7 @@ namespace etl { data_node_t* p_node = p_node_pool->allocate(); ::new (&(p_node->value)) T(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return *p_node; } @@ -1338,7 +1338,7 @@ namespace etl { node.value.~T(); p_node_pool->release(&node); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } // Disable copy construction. diff --git a/include/etl/list.h b/include/etl/list.h index 174e2b6b..42aaaeb2 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -317,10 +317,10 @@ namespace etl { } - etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. - node_t terminal_node; ///< The node that acts as the list start and end. - const size_type MAX_SIZE; ///< The maximum size of the list. - etl::debug_count construct_count; ///< Internal debugging. + etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. + node_t terminal_node; ///< The node that acts as the list start and end. + const size_type MAX_SIZE; ///< The maximum size of the list. + ETL_DECLARE_DEBUG_COUNT; ///< Internal debugging. }; //*************************************************************************** @@ -789,7 +789,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(get_head(), *p_data_node); } @@ -804,7 +804,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(get_head(), *p_data_node); } @@ -819,7 +819,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(get_head(), *p_data_node); } @@ -834,7 +834,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3, value4); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(get_head(), *p_data_node); } @@ -880,7 +880,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(terminal_node, *p_data_node); } @@ -895,7 +895,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(terminal_node, *p_data_node); } @@ -910,7 +910,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(terminal_node, *p_data_node); } @@ -925,7 +925,7 @@ namespace etl #endif data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3, value4); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(terminal_node, *p_data_node); } @@ -964,7 +964,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -980,7 +980,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -996,7 +996,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -1012,7 +1012,7 @@ namespace etl data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value1, value2, value3, value4); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; insert_node(*position.p_node, *p_data_node); return iterator(*p_data_node); @@ -1456,7 +1456,7 @@ namespace etl if ETL_IF_CONSTEXPR(etl::is_trivially_destructible::value) { p_node_pool->release_all(); - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; } else { @@ -1549,7 +1549,7 @@ namespace etl { data_node_t* p_data_node = p_node_pool->allocate(); ::new (&(p_data_node->value)) T(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return *p_data_node; } @@ -1561,7 +1561,7 @@ namespace etl { node.value.~T(); p_node_pool->release(&node); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } // Disable copy construction. diff --git a/include/etl/map.h b/include/etl/map.h index 276457f4..6f1908e0 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -453,7 +453,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type CAPACITY; ///< The maximum size of the map. Node* root_node; ///< The node that acts as the map root. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; }; //*************************************************************************** @@ -1263,7 +1263,7 @@ namespace etl { Data_Node& node = *p_node_pool->allocate(); ::new (&node.value) const value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return node; } @@ -1274,7 +1274,7 @@ namespace etl { node.value.~value_type(); p_node_pool->release(&node); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //************************************************************************* diff --git a/include/etl/memory_model.h b/include/etl/memory_model.h new file mode 100644 index 00000000..07bfc73f --- /dev/null +++ b/include/etl/memory_model.h @@ -0,0 +1,46 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_MEMORY_MODEL_INCLUDED +#define ETL_MEMORY_MODEL_INCLUDED + +#include "user_type.h" + +namespace etl +{ + ETL_DECLARE_USER_TYPE(memory_model, int) + ETL_USER_TYPE(MM_SMALL, 0) + ETL_USER_TYPE(MM_MEDIUM, 1) + ETL_USER_TYPE(MM_LARGE, 2) + ETL_END_USER_TYPE(memory_model) +} + +#endif + diff --git a/include/etl/multimap.h b/include/etl/multimap.h index b855e2cd..91aca760 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -609,7 +609,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type CAPACITY; ///< The maximum size of the map. Node* root_node; ///< The node that acts as the multimap root. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; }; //*************************************************************************** @@ -1356,7 +1356,7 @@ namespace etl { Data_Node& node = *p_node_pool->allocate(); ::new (&node.value) const value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return node; } @@ -1367,7 +1367,7 @@ namespace etl { node.value.~value_type(); p_node_pool->release(&node); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //************************************************************************* diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 23eed65d..4b6a74e0 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -609,7 +609,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type CAPACITY; ///< The maximum size of the set. Node* root_node; ///< The node that acts as the multiset root. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; }; //*************************************************************************** @@ -1337,7 +1337,7 @@ namespace etl { Data_Node& node = *p_node_pool->allocate(); ::new ((void*)&node.value) value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return node; } @@ -1348,7 +1348,7 @@ namespace etl { node.value.~value_type(); p_node_pool->release(&node); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //************************************************************************* diff --git a/include/etl/private/vector_base.h b/include/etl/private/vector_base.h index 6839e67a..d34b4f68 100644 --- a/include/etl/private/vector_base.h +++ b/include/etl/private/vector_base.h @@ -161,8 +161,8 @@ namespace etl { } - const size_type CAPACITY; ///allocate(); ::new ((void*)&node.value) value_type(value); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; return node; } @@ -1197,7 +1197,7 @@ namespace etl { node.value.~value_type(); p_node_pool->release(&node); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //************************************************************************* diff --git a/include/etl/stack.h b/include/etl/stack.h index 57e40dde..3f9e1612 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -178,7 +178,7 @@ namespace etl void add_in() { top_index = current_size++; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -188,7 +188,7 @@ namespace etl { --top_index; --current_size; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } //************************************************************************* @@ -198,13 +198,13 @@ namespace etl { top_index = 0; current_size = 0; - construct_count.clear(); + ETL_RESET_DEBUG_COUNT; } - size_type top_index; ///< The index of the top of the stack. - size_type current_size; ///< The number of items in the stack. - const size_type CAPACITY; ///< The maximum number of items in the stack. - etl::debug_count construct_count; ///< For internal debugging purposes. + size_type top_index; ///< The index of the top of the stack. + size_type current_size; ///< The number of items in the stack. + const size_type CAPACITY; ///< The maximum number of items in the stack. + ETL_DECLARE_DEBUG_COUNT; ///< For internal debugging purposes. }; //*************************************************************************** diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index c5dd51e0..0f757b0e 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -658,7 +658,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key_value_pair) value_type(key, T()); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; pbucket->insert_after(pbucket->before_begin(), node); @@ -788,7 +788,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key_value_pair) value_type(key_value_pair); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); @@ -822,7 +822,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key_value_pair) value_type(key_value_pair); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); @@ -892,7 +892,7 @@ namespace etl icurrent->key_value_pair.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. n = 1; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } return n; @@ -921,7 +921,7 @@ namespace etl bucket.erase_after(iprevious); // Unlink from the bucket. icurrent->key_value_pair.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; return inext; } @@ -956,7 +956,7 @@ namespace etl local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. icurrent->key_value_pair.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; icurrent = inext; @@ -1224,7 +1224,7 @@ namespace etl { // Destroy the value contents. it->key_value_pair.~value_type(); - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; ++it; } @@ -1282,7 +1282,7 @@ namespace etl key_equal key_equal_function; /// For library debugging purposes only. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index 1bec644d..25257d39 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -677,7 +677,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key_value_pair) value_type(key_value_pair); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); @@ -707,7 +707,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key_value_pair) value_type(key_value_pair); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); @@ -770,7 +770,7 @@ namespace etl pnodepool->release(&*icurrent); // Release it back to the pool. ++n; icurrent = iprevious; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } else { @@ -806,7 +806,7 @@ namespace etl bucket.erase_after(iprevious); // Unlink from the bucket. icurrent->key_value_pair.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; return inext; } @@ -841,7 +841,7 @@ namespace etl local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. icurrent->key_value_pair.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; icurrent = inext; @@ -1136,7 +1136,7 @@ namespace etl // Destroy the value contents. it->key_value_pair.~value_type(); ++it; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } // Now it's safe to clear the bucket. @@ -1192,7 +1192,7 @@ namespace etl key_equal key_equal_function; /// For library debugging purposes only. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 1301f40a..11cbc07a 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -669,7 +669,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key) value_type(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); @@ -700,7 +700,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key) value_type(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); @@ -764,7 +764,7 @@ namespace etl pnodepool->release(&*icurrent); // Release it back to the pool. ++n; icurrent = iprevious; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } else { @@ -800,7 +800,7 @@ namespace etl bucket.erase_after(iprevious); // Unlink from the bucket. icurrent->key.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; return inext; } @@ -835,7 +835,7 @@ namespace etl local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. icurrent->key.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; icurrent = inext; @@ -1130,7 +1130,7 @@ namespace etl // Destroy the value contents. it->key.~value_type(); ++it; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } // Now it's safe to clear the bucket. @@ -1186,7 +1186,7 @@ namespace etl key_equal key_equal_function; /// For library debugging purposes only. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index d1b7000f..94473567 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -670,7 +670,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key) value_type(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); @@ -704,7 +704,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); ::new (&node.key) value_type(key); - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); @@ -774,7 +774,7 @@ namespace etl icurrent->key.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. n = 1; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } return n; @@ -803,7 +803,7 @@ namespace etl bucket.erase_after(iprevious); // Unlink from the bucket. icurrent->key.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; return inext; } @@ -838,7 +838,7 @@ namespace etl local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. icurrent->key.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; icurrent = inext; @@ -1107,7 +1107,7 @@ namespace etl // Destroy the value contents. it->key.~value_type(); ++it; - --construct_count; + ETL_DECREMENT_DEBUG_COUNT; } // Now it's safe to clear the bucket. @@ -1163,7 +1163,7 @@ namespace etl key_equal key_equal_function; /// For library debugging purposes only. - etl::debug_count construct_count; + ETL_DECLARE_DEBUG_COUNT; //************************************************************************* /// Destructor. diff --git a/include/etl/vector.h b/include/etl/vector.h index 78be2370..41683a93 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -5,7 +5,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2014 jwellbelove @@ -233,16 +233,12 @@ namespace etl if (current_size < new_size) { etl::uninitialized_fill_n(p_end, delta, value); -#if defined(ETL_DEBUG) - construct_count += delta; -#endif + ETL_ADD_DEBUG_COUNT(delta); } else { etl::destroy_n(p_end - delta, delta); -#if defined(ETL_DEBUG) - construct_count -= delta; -#endif + ETL_SUBTRACT_DEBUG_COUNT(delta); } p_end = p_buffer + new_size; @@ -372,11 +368,8 @@ namespace etl initialise(); -#if defined(ETL_DEBUG) - p_end = etl::uninitialized_copy(first, last, p_buffer, construct_count); -#else p_end = etl::uninitialized_copy(first, last, p_buffer); -#endif + ETL_ADD_DEBUG_COUNT(uint32_t(std::distance(first, last))); } //********************************************************************* @@ -391,11 +384,8 @@ namespace etl initialise(); -#if defined(ETL_DEBUG) - p_end = etl::uninitialized_fill_n(p_buffer, n, value, construct_count); -#else p_end = etl::uninitialized_fill_n(p_buffer, n, value); -#endif + ETL_ADD_DEBUG_COUNT(uint32_t(n)); } //************************************************************************* @@ -445,7 +435,7 @@ namespace etl #endif ::new (p_end) T(value1); ++p_end; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -461,7 +451,7 @@ namespace etl #endif ::new (p_end) T(value1, value2); ++p_end; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -477,7 +467,7 @@ namespace etl #endif ::new (p_end) T(value1, value2, value3); ++p_end; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //********************************************************************* @@ -493,7 +483,7 @@ namespace etl #endif ::new (p_end) T(value1, value2, value3, value4); ++p_end; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } //************************************************************************* @@ -545,7 +535,7 @@ namespace etl if (position == end()) { p = p_end++; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } else { @@ -573,7 +563,7 @@ namespace etl if (position == end()) { p = p_end++; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } else { @@ -601,7 +591,7 @@ namespace etl if (position == end()) { p = p_end++; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } else { @@ -629,7 +619,7 @@ namespace etl if (position == end()) { p = p_end++; - ++construct_count; + ETL_INCREMENT_DEBUG_COUNT; } else { @@ -680,31 +670,19 @@ namespace etl size_t copy_new_n = construct_old_n; size_t construct_new_n = insert_n - copy_new_n; -#if defined(ETL_DEBUG) - // Construct old. - etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old, construct_count); - - // Copy old. - etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); - - // Construct new. - etl::uninitialized_fill_n(p_end, construct_new_n, value, construct_count); - - // Copy new. - std::fill_n(p_buffer + insert_begin, copy_new_n, value); -#else // Construct old. etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old); + ETL_ADD_DEBUG_COUNT(construct_old_n); // Copy old. etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); // Construct new. etl::uninitialized_fill_n(p_end, construct_new_n, value); + ETL_ADD_DEBUG_COUNT(construct_new_n); // Copy new. std::fill_n(p_buffer + insert_begin, copy_new_n, value); -#endif p_end += n; } @@ -749,31 +727,19 @@ namespace etl size_t copy_new_n = construct_old_n; size_t construct_new_n = insert_n - copy_new_n; -#if defined(ETL_DEBUG) - // Construct old. - etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old, construct_count); - - // Copy old. - etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); - - // Construct new. - etl::uninitialized_copy_n(first + copy_new_n, construct_new_n, p_end, construct_count); - - // Copy new. - etl::copy_n(first, copy_new_n, p_buffer + insert_begin); -#else // Construct old. etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old); + ETL_ADD_DEBUG_COUNT(construct_old_n); // Copy old. etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); // Construct new. etl::uninitialized_copy_n(first + copy_new_n, construct_new_n, p_end); + ETL_ADD_DEBUG_COUNT(construct_new_n); // Copy new. etl::copy_n(first, copy_new_n, p_buffer + insert_begin); -#endif p_end += count; } @@ -811,11 +777,8 @@ namespace etl size_t n_delete = std::distance(first, last); // Destroy the elements left over at the end. -#if defined(ETL_DEBUG) - etl::destroy(p_end - n_delete, p_end, construct_count); -#else etl::destroy(p_end - n_delete, p_end); -#endif + ETL_SUBTRACT_DEBUG_COUNT(n_delete); p_end -= n_delete; } @@ -895,11 +858,8 @@ namespace etl //********************************************************************* void initialise() { -#if defined(ETL_DEBUG) - etl::destroy(p_buffer, p_end, construct_count); -#else etl::destroy(p_buffer, p_end); -#endif + ETL_SUBTRACT_DEBUG_COUNT(int32_t(std::distance(p_buffer, p_end))); p_end = p_buffer; } @@ -924,11 +884,9 @@ namespace etl //********************************************************************* inline void create_back() { -#if defined(ETL_DEBUG) - etl::create_value_at(p_end, construct_count); -#else etl::create_value_at(p_end); -#endif + ETL_INCREMENT_DEBUG_COUNT; + ++p_end; } @@ -937,11 +895,9 @@ namespace etl //********************************************************************* inline void create_back(parameter_t value) { -#if defined(ETL_DEBUG) - etl::create_copy_at(p_end, value, construct_count); -#else etl::create_copy_at(p_end, value); -#endif + ETL_INCREMENT_DEBUG_COUNT; + ++p_end; } @@ -952,11 +908,8 @@ namespace etl { --p_end; -#if defined(ETL_DEBUG) - etl::destroy_at(p_end, construct_count); -#else etl::destroy_at(p_end); -#endif + ETL_DECREMENT_DEBUG_COUNT; } // Disable copy construction. diff --git a/test/etl_profile.h b/test/etl_profile.h index 96636ff8..906660b9 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -38,6 +38,7 @@ SOFTWARE. #define ETL_IVECTOR_REPAIR_ENABLE #define ETL_IDEQUE_REPAIR_ENABLE #define ETL_IN_UNIT_TEST +#define ETL_DEBUG_COUNT #define ETL_MESSAGE_TIMER_USE_ATOMIC_LOCK #define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK diff --git a/test/test_queue_mpmc_mutex.cpp b/test/test_queue_mpmc_mutex.cpp index b9f39105..9b8b7bee 100644 --- a/test/test_queue_mpmc_mutex.cpp +++ b/test/test_queue_mpmc_mutex.cpp @@ -45,6 +45,42 @@ SOFTWARE. namespace { + struct Data + { + Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4) + : a(a_), + b(b_), + c(c_), + d(d_) + { + } + + Data() + : a(0), + b(0), + c(0), + d(0) + { + } + + int a; + int b; + int c; + int d; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } + + std::ostream& operator <<(std::ostream& os, const Data& data) + { + os << data.a << " " << data.b << " " << data.c << " " << data.d; + + return os; + } + SUITE(test_queue_mpmc_mutex) { //************************************************************************* @@ -371,7 +407,7 @@ namespace std::thread t2(push_thread2); std::thread t3(pop_thread1); std::thread t4(pop_thread2); - + start.store(true); // Join the threads with the main thread diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index 767c9004..abb1b7a1 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -337,6 +337,7 @@ + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 273aa52f..eb3e8c7a 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -627,6 +627,9 @@ ETL\Utilities\Generators + + ETL\Utilities +