- 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.
This commit is contained in:
ExMix 2015-11-01 21:02:14 +03:00 committed by r.kuznetsov
parent a9b3f5213b
commit f30b34283d
6 changed files with 41 additions and 7 deletions

View file

@ -5,7 +5,7 @@ namespace df
void MemoryFeatureIndex::ReadFeaturesRequest(TFeaturesInfo & features, vector<FeatureID> & featuresToRead)
{
threads::MutexGuard lock(m_mutex);
ASSERT(m_isLocked, ());
for (FeatureInfo & info : features)
{
@ -20,7 +20,7 @@ void MemoryFeatureIndex::ReadFeaturesRequest(TFeaturesInfo & features, vector<Fe
void MemoryFeatureIndex::RemoveFeatures(TFeaturesInfo & features)
{
threads::MutexGuard lock(m_mutex);
ASSERT(m_isLocked, ());
for (FeatureInfo & info : features)
{

View file

@ -39,10 +39,29 @@ using TFeaturesInfo = buffer_vector<FeatureInfo, AverageFeaturesCount>;
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<FeatureID> & featuresToRead);
void RemoveFeatures(TFeaturesInfo & features);
private:
bool m_isLocked = false;
threads::Mutex m_mutex;
set<FeatureID> m_features;
};

View file

@ -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

View file

@ -23,6 +23,7 @@ public:
void Init(shared_ptr<TileInfo> const & tileInfo);
void Reset();
bool IsCancelled() const override;
TileKey GetTileKey() const;
private:

View file

@ -27,8 +27,6 @@ m2::RectD TileInfo::GetGlobalRect() const
void TileInfo::ReadFeatureIndex(MapDataProvider const & model)
{
lock_guard<mutex> lock(m_mutex);
if (DoNeedReadIndex())
{
CheckCanceled();
@ -63,7 +61,9 @@ void TileInfo::ReadFeatures(MapDataProvider const & model, MemoryFeatureIndex &
vector<FeatureID> featuresToRead;
{
lock_guard<mutex> 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<mutex> 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);

View file

@ -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<bool> m_isCanceled;
mutex m_mutex;
};
} // namespace df