From 1fba8663d84ae59cedd41bbded7ed6eb3189b791 Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 10 Jan 2012 15:48:44 +0400 Subject: [PATCH] added debugging to StoragePool and fixed primaryStorage consumer starvation deadlock. --- base/resource_pool.hpp | 22 ++++++++++++++++++++-- base/threaded_list.hpp | 5 +++++ map/framework.cpp | 1 + map/screen_coverage.cpp | 2 +- map/tiling_render_policy_st.cpp | 6 ++++-- yg/resource_manager.cpp | 11 ++++++++--- yg/resource_manager.hpp | 5 ++++- 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/base/resource_pool.hpp b/base/resource_pool.hpp index 7f6d4e04ea..7b0f615ca5 100644 --- a/base/resource_pool.hpp +++ b/base/resource_pool.hpp @@ -21,11 +21,12 @@ struct BasePoolTraits { TElemFactory m_factory; ThreadedList m_pool; + bool m_IsDebugging; typedef TElem elem_t; BasePoolTraits(TElemFactory const & factory) - : m_factory(factory) + : m_factory(factory), m_IsDebugging(false) { m_pool.SetName(factory.ResName()); } @@ -68,14 +69,22 @@ struct SeparateFreePoolTraits : TBase typedef typename base_t::elem_t elem_t; ThreadedList m_freePool; + int m_maxFreePoolSize; SeparateFreePoolTraits(TElemFactory const & factory) - : base_t(factory) + : base_t(factory), m_maxFreePoolSize(0) {} void Free(elem_t const & elem) { m_freePool.PushBack(elem); + if (base_t::m_IsDebugging) + { + int oldMaxFreePoolSize = m_maxFreePoolSize; + m_maxFreePoolSize = max(m_maxFreePoolSize, (int)m_freePool.Size()); + if (oldMaxFreePoolSize != m_maxFreePoolSize) + LOG(LINFO, ("freePool maximum size has reached", m_maxFreePoolSize, "elements")); + } } void MergeImpl(list & l) @@ -88,6 +97,9 @@ struct SeparateFreePoolTraits : TBase base_t::m_pool.PushBack(*it); } +// if ((base_t::m_IsDebugging) && (!base_t::m_pool.GetName().empty())) +// LOG(LINFO, ("pool for", base_t::m_pool.GetName(), "has", base_t::m_pool.Size(), "elements")); + l.clear(); } @@ -178,6 +190,7 @@ public: virtual void Cancel() = 0; virtual bool IsCancelled() const = 0; virtual void Merge() = 0; + virtual void SetIsDebugging(bool flag) = 0; }; // This class tracks OpenGL resources allocation in @@ -236,4 +249,9 @@ public: { m_traits->Merge(); } + + void SetIsDebugging(bool isDebugging) + { + m_traits->m_IsDebugging = isDebugging; + } }; diff --git a/base/threaded_list.hpp b/base/threaded_list.hpp index e72961004f..50c6c4f809 100644 --- a/base/threaded_list.hpp +++ b/base/threaded_list.hpp @@ -71,6 +71,11 @@ public: m_resName = name; } + string const & GetName() const + { + return m_resName; + } + bool WaitNonEmpty() { double StartWaitTime = m_Timer.ElapsedSeconds(); diff --git a/map/framework.cpp b/map/framework.cpp index aff475d5bd..91b1ec4d78 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -203,6 +203,7 @@ bool Framework::IsEmptyModel() const void Framework::PrepareToShutdown() { + SetRenderPolicy(0); } void Framework::SetMaxWorldRect() diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp index d40ab849bb..2bac0c6d99 100644 --- a/map/screen_coverage.cpp +++ b/map/screen_coverage.cpp @@ -257,7 +257,7 @@ void ScreenCoverage::Draw(yg::gl::Screen * s, ScreenBase const & screen) if (m_stylesCache) s->setAdditionalSkinPage(m_stylesCache->cachePage()); - m_infoLayer.draw(s, m_screen.PtoGMatrix() * screen.GtoPMatrix()); + m_infoLayer.draw(s, m_screen.PtoGMatrix() * screen.GtoPMatrix()); } void ScreenCoverage::EndFrame(yg::gl::Screen *s) diff --git a/map/tiling_render_policy_st.cpp b/map/tiling_render_policy_st.cpp index 97d8d20219..fe26164e0d 100644 --- a/map/tiling_render_policy_st.cpp +++ b/map/tiling_render_policy_st.cpp @@ -42,11 +42,12 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, sizeof(yg::gl::Vertex), 10000 * sizeof(unsigned short), sizeof(unsigned short), - 12, + 60, true, false, 2, - "primaryStorage"); + "primaryStorage", + true); rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(2000 * sizeof(yg::gl::Vertex), sizeof(yg::gl::Vertex), @@ -169,6 +170,7 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer, p.m_visualScale = GetPlatform().VisualScale(); p.m_useGuiResources = true; p.m_isSynchronized = false; +// p.m_isDebugging = true; m_drawer.reset(new DrawerYG(p)); diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index 2c577bb23d..19f310b854 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -98,7 +98,8 @@ namespace yg m_isFixedBufferSize(true), m_isFixedBufferCount(true), m_scalePriority(0), - m_poolName(poolName) + m_poolName(poolName), + m_isDebugging(false) {} ResourceManager::StoragePoolParams::StoragePoolParams(size_t vbSize, @@ -109,7 +110,8 @@ namespace yg bool isFixedBufferSize, bool isFixedBufferCount, int scalePriority, - string const & poolName) + string const & poolName, + bool isDebugging) : m_vbSize(vbSize), m_vertexSize(vertexSize), m_ibSize(ibSize), @@ -118,7 +120,8 @@ namespace yg m_isFixedBufferSize(isFixedBufferSize), m_isFixedBufferCount(isFixedBufferCount), m_scalePriority(scalePriority), - m_poolName(poolName) + m_poolName(poolName), + m_isDebugging(isDebugging) {} bool ResourceManager::StoragePoolParams::isFixed() const @@ -492,6 +495,8 @@ namespace yg pool.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str()), p.m_storagesCount))); else pool.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str()), p.m_storagesCount))); + + pool->SetIsDebugging(p.m_isDebugging); } else LOG(LINFO, ("no ", p.m_poolName, " resource")); diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index aa1356398a..1ca5bef1bf 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -89,6 +89,8 @@ namespace yg string m_poolName; + bool m_isDebugging; + StoragePoolParams(size_t vbSize, size_t vertexSize, size_t ibSize, @@ -97,7 +99,8 @@ namespace yg bool isFixedBufferSize, bool isFixedBufferCount, int scalePriority, - string const & poolName); + string const & poolName, + bool isDebugging = false); StoragePoolParams(string const & poolName);