diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp index 7959c41228..6752dc8ec6 100644 --- a/map/screen_coverage.cpp +++ b/map/screen_coverage.cpp @@ -466,6 +466,7 @@ void ScreenCoverage::RemoveTiles(m2::AnyRectD const & r, int startScale) } TileCache * tileCache = &m_tileRenderer->GetTileCache(); + tileCache->Lock(); for (vector::const_iterator it = toRemove.begin(); it != toRemove.end(); ++it) { @@ -474,6 +475,7 @@ void ScreenCoverage::RemoveTiles(m2::AnyRectD const & r, int startScale) m_tiles.erase(*it); m_tileRects.erase(ri); } + tileCache->Unlock(); MergeOverlay(); } diff --git a/map/tile_cache.cpp b/map/tile_cache.cpp index 802fc3d93f..3cc44d2edd 100644 --- a/map/tile_cache.cpp +++ b/map/tile_cache.cpp @@ -13,21 +13,24 @@ TileCache::Entry::Entry(Tile const & tile, shared_ptr : m_tile(tile), m_rm(rm) {} -TileCache::TileCache() +TileCache::TileCache() : m_isLocked(false) {} void TileCache::AddTile(Tiler::RectInfo const & key, Entry const & entry) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.Add(key, entry, 1); } void TileCache::Lock() { m_lock.Lock(); + m_isLocked = true; } void TileCache::Unlock() { + m_isLocked = false; m_lock.Unlock(); } @@ -49,36 +52,43 @@ set const & TileCache::Keys() const bool TileCache::HasTile(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); return m_cache.HasElem(key); } void TileCache::LockTile(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.LockElem(key); } size_t TileCache::LockCount(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); return m_cache.LockCount(key); } void TileCache::UnlockTile(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.UnlockElem(key); } void TileCache::TouchTile(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.Touch(key); } Tile const & TileCache::GetTile(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); return m_cache.Find(key).m_tile; } void TileCache::Remove(Tiler::RectInfo const & key) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.Remove(key); } @@ -89,11 +99,13 @@ int TileCache::CanFit() const int TileCache::UnlockedWeight() const { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); return m_cache.UnlockedWeight(); } int TileCache::LockedWeight() const { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); return m_cache.LockedWeight(); } @@ -104,10 +116,12 @@ int TileCache::CacheSize() const void TileCache::Resize(int maxWeight) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.Resize(maxWeight); } void TileCache::FreeRoom(int weight) { + ASSERT(m_isLocked, ("TileCache need to be locked on modify")); m_cache.FreeRoom(weight); } diff --git a/map/tile_cache.hpp b/map/tile_cache.hpp index 7bd5fb8432..3e82ab428c 100644 --- a/map/tile_cache.hpp +++ b/map/tile_cache.hpp @@ -36,6 +36,7 @@ private: my::MRUCache m_cache; threads::Mutex m_lock; + bool m_isLocked; TileCache(TileCache const & src); TileCache const & operator=(TileCache const & src); diff --git a/map/tile_renderer.cpp b/map/tile_renderer.cpp index 9ac7531b70..4fd6070f68 100644 --- a/map/tile_renderer.cpp +++ b/map/tile_renderer.cpp @@ -342,6 +342,7 @@ TileCache & TileRenderer::GetTileCache() void TileRenderer::CacheActiveTile(Tiler::RectInfo const & rectInfo) { + TileStructuresLockGuard guard(m_tileCache, m_tileSet); if (m_tileSet.HasTile(rectInfo)) { ASSERT(!m_tileCache.HasTile(rectInfo), (""));