diff --git a/drape_frontend/batchers_pool.cpp b/drape_frontend/batchers_pool.cpp index ee38a29ae6..0bf7fe7865 100644 --- a/drape_frontend/batchers_pool.cpp +++ b/drape_frontend/batchers_pool.cpp @@ -73,6 +73,13 @@ namespace df void BatchersPool::ReserveBatcher(TileKey const & key) { + reserved_batchers_t::iterator it = m_reservedBatchers.find(key); + if (it != m_reservedBatchers.end()) + { + it->second.second++; + return; + } + MasterPointer reserved; if (m_batchers.empty()) reserved.Reset(new Batcher()); @@ -83,7 +90,7 @@ namespace df } reserved->StartSession(bind(&FlushGeometry, m_sendMessageFn, key, _1, _2)); - VERIFY(m_reservedBatchers.insert(make_pair(key, reserved)).second, ()); + VERIFY(m_reservedBatchers.insert(make_pair(key, make_pair(reserved, 1))).second, ()); } RefPointer BatchersPool::GetTileBatcher(TileKey const & key) @@ -91,7 +98,7 @@ namespace df reserved_batchers_t::iterator it = m_reservedBatchers.find(key); ASSERT(it != m_reservedBatchers.end(), ()); - return it->second.GetRefPointer(); + return it->second.first.GetRefPointer(); } void BatchersPool::ReleaseBatcher(TileKey const & key) @@ -99,9 +106,12 @@ namespace df reserved_batchers_t::iterator it = m_reservedBatchers.find(key); ASSERT(it != m_reservedBatchers.end(), ()); - MasterPointer batcher = it->second; - batcher->EndSession(); - m_reservedBatchers.erase(it); - m_batchers.push(batcher); + if ((--it->second.second)== 0) + { + MasterPointer batcher = it->second.first; + batcher->EndSession(); + m_reservedBatchers.erase(it); + m_batchers.push(batcher); + } } } diff --git a/drape_frontend/batchers_pool.hpp b/drape_frontend/batchers_pool.hpp index 0c71859b78..9137903f9b 100644 --- a/drape_frontend/batchers_pool.hpp +++ b/drape_frontend/batchers_pool.hpp @@ -13,6 +13,7 @@ class Batcher; namespace df { class Message; + // Not thread safe class BatchersPool { public: @@ -29,8 +30,12 @@ namespace df void ReleaseBatcher(TileKey const & key); private: - stack > m_batchers; - typedef map > reserved_batchers_t; + typedef MasterPointer batcher_ptr; + typedef stack batchers_pool_t; + typedef pair counted_batcher_t; + typedef map reserved_batchers_t; + + batchers_pool_t m_batchers; reserved_batchers_t m_reservedBatchers; send_message_fn m_sendMessageFn;