From f30b34283d952a35e2757c510b893fdc4e58c3ae Mon Sep 17 00:00:00 2001 From: ExMix Date: Sun, 1 Nov 2015 21:02:14 +0300 Subject: [PATCH] [drape] - remove mutex from TileInfo. Now TileInfo use mutex of MemoryFeatureIndex to sync with BR thread. - ReadMWMTask bug. Before this fix we canceled only TileInfo, but ReadMWMTask state did't take account of TileInfo state. --- drape_frontend/memory_feature_index.cpp | 4 ++-- drape_frontend/memory_feature_index.hpp | 19 +++++++++++++++++++ drape_frontend/read_mwm_task.cpp | 8 ++++++++ drape_frontend/read_mwm_task.hpp | 1 + drape_frontend/tile_info.cpp | 14 ++++++++++---- drape_frontend/tile_info.hpp | 2 +- 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/drape_frontend/memory_feature_index.cpp b/drape_frontend/memory_feature_index.cpp index 3cf398ce47..65adb4750a 100644 --- a/drape_frontend/memory_feature_index.cpp +++ b/drape_frontend/memory_feature_index.cpp @@ -5,7 +5,7 @@ namespace df void MemoryFeatureIndex::ReadFeaturesRequest(TFeaturesInfo & features, vector & featuresToRead) { - threads::MutexGuard lock(m_mutex); + ASSERT(m_isLocked, ()); for (FeatureInfo & info : features) { @@ -20,7 +20,7 @@ void MemoryFeatureIndex::ReadFeaturesRequest(TFeaturesInfo & features, vector; class MemoryFeatureIndex : private noncopyable { public: + class Lock + { + threads::MutexGuard lock; + MemoryFeatureIndex & m_index; + public: + Lock(MemoryFeatureIndex & index) + : lock(index.m_mutex) + , m_index(index) + { + m_index.m_isLocked = true; + } + + ~Lock() + { + m_index.m_isLocked = false; + } + }; + void ReadFeaturesRequest(TFeaturesInfo & features, vector & featuresToRead); void RemoveFeatures(TFeaturesInfo & features); private: + bool m_isLocked = false; threads::Mutex m_mutex; set m_features; }; diff --git a/drape_frontend/read_mwm_task.cpp b/drape_frontend/read_mwm_task.cpp index d84accba03..adc039af07 100644 --- a/drape_frontend/read_mwm_task.cpp +++ b/drape_frontend/read_mwm_task.cpp @@ -27,6 +27,14 @@ void ReadMWMTask::Reset() m_tileInfo.reset(); } +bool ReadMWMTask::IsCancelled() const +{ + if (m_tileInfo == nullptr) + return true; + + return m_tileInfo->IsCancelled() || IRoutine::IsCancelled(); +} + void ReadMWMTask::Do() { #ifdef DEBUG diff --git a/drape_frontend/read_mwm_task.hpp b/drape_frontend/read_mwm_task.hpp index 8659bee1fb..97575c868f 100644 --- a/drape_frontend/read_mwm_task.hpp +++ b/drape_frontend/read_mwm_task.hpp @@ -23,6 +23,7 @@ public: void Init(shared_ptr const & tileInfo); void Reset(); + bool IsCancelled() const override; TileKey GetTileKey() const; private: diff --git a/drape_frontend/tile_info.cpp b/drape_frontend/tile_info.cpp index c8ffe1d353..53c236d07a 100644 --- a/drape_frontend/tile_info.cpp +++ b/drape_frontend/tile_info.cpp @@ -27,8 +27,6 @@ m2::RectD TileInfo::GetGlobalRect() const void TileInfo::ReadFeatureIndex(MapDataProvider const & model) { - lock_guard lock(m_mutex); - if (DoNeedReadIndex()) { CheckCanceled(); @@ -63,7 +61,9 @@ void TileInfo::ReadFeatures(MapDataProvider const & model, MemoryFeatureIndex & vector featuresToRead; { - lock_guard g(m_mutex); + MemoryFeatureIndex::Lock lock(memIndex); + UNUSED_VALUE(lock); + CheckCanceled(); featuresToRead.reserve(AverageFeaturesCount); memIndex.ReadFeaturesRequest(m_featureInfo, featuresToRead); @@ -79,10 +79,16 @@ void TileInfo::ReadFeatures(MapDataProvider const & model, MemoryFeatureIndex & void TileInfo::Cancel(MemoryFeatureIndex & memIndex) { m_isCanceled = true; - lock_guard lock(m_mutex); + MemoryFeatureIndex::Lock lock(memIndex); + UNUSED_VALUE(lock); memIndex.RemoveFeatures(m_featureInfo); } +bool TileInfo::IsCancelled() const +{ + return m_isCanceled; +} + void TileInfo::ProcessID(FeatureID const & id) { m_featureInfo.push_back(id); diff --git a/drape_frontend/tile_info.hpp b/drape_frontend/tile_info.hpp index 2d1f1128b9..3c5478973c 100644 --- a/drape_frontend/tile_info.hpp +++ b/drape_frontend/tile_info.hpp @@ -29,6 +29,7 @@ public: void ReadFeatures(MapDataProvider const & model, MemoryFeatureIndex & memIndex); void Cancel(MemoryFeatureIndex & memIndex); + bool IsCancelled() const; m2::RectD GetGlobalRect() const; TileKey const & GetTileKey() const { return m_context->GetTileKey(); } @@ -48,7 +49,6 @@ private: TFeaturesInfo m_featureInfo; atomic m_isCanceled; - mutex m_mutex; }; } // namespace df