Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpimenov <mpimenov@users.noreply.github.com>2016-06-03 16:38:39 +0300
committermpimenov <mpimenov@users.noreply.github.com>2016-06-03 16:38:39 +0300
commitee760136204d2ef8dbc5315077efa2e6781e1992 (patch)
tree7189796c2a9b1fddf94ff8d214d650c671ff016c /indexer/index.hpp
parent4d09cea1bc34d4fb9afd60354c6074c45db741ad (diff)
parent85ee45b48220988cb098e20268000d361434c4e2 (diff)
Merge pull request #3428 from ygorshenin/fixed-massive-descriptors-leaks
[index] Fixed massive descriptors leaks.
Diffstat (limited to 'indexer/index.hpp')
-rw-r--r--indexer/index.hpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/indexer/index.hpp b/indexer/index.hpp
index eb850cafd1..f57c62adc3 100644
--- a/indexer/index.hpp
+++ b/indexer/index.hpp
@@ -19,12 +19,23 @@
#include "std/limits.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
-
+#include "std/weak_ptr.hpp"
class MwmInfoEx : public MwmInfo
{
-public:
- unique_ptr<feature::FeaturesOffsetsTable> m_table;
+private:
+ friend class Index;
+ friend class MwmValue;
+
+ // weak_ptr is needed here to access offsets table in already
+ // instantiated MwmValue-s for the MWM, including MwmValues in the
+ // MwmSet's cache. We can't use shared_ptr because of offsets table
+ // must be removed as soon as the last corresponding MwmValue is
+ // destroyed. Also, note that this value must be used and modified
+ // only in MwmValue::SetTable() method, which, in turn, is called
+ // only in the MwmSet critical section, protected by a lock. So,
+ // there's an implicit synchronization on this field.
+ weak_ptr<feature::FeaturesOffsetsTable> m_table;
};
class MwmValue : public MwmSet::MwmValueBase
@@ -33,7 +44,8 @@ public:
FilesContainerR const m_cont;
IndexFactory m_factory;
platform::LocalCountryFile const m_file;
- feature::FeaturesOffsetsTable const * m_table;
+
+ shared_ptr<feature::FeaturesOffsetsTable> m_table;
explicit MwmValue(platform::LocalCountryFile const & localFile);
void SetTable(MwmInfoEx & info);
@@ -97,7 +109,7 @@ private:
covering::IntervalsT const & interval = cov.Get(lastScale);
// Prepare features reading.
- FeaturesVector const fv(pValue->m_cont, header, pValue->m_table);
+ FeaturesVector const fv(pValue->m_cont, header, pValue->m_table.get());
ScaleIndex<ModelReaderPtr> index(pValue->m_cont.GetReader(INDEX_FILE_TAG),
pValue->m_factory);
@@ -226,7 +238,8 @@ public:
if (handle.IsAlive())
{
MwmValue const * pValue = handle.GetValue<MwmValue>();
- FeaturesVector const featureReader(pValue->m_cont, pValue->GetHeader(), pValue->m_table);
+ FeaturesVector const featureReader(pValue->m_cont, pValue->GetHeader(),
+ pValue->m_table.get());
do
{
osm::Editor::FeatureStatus const fts = editor.GetFeatureStatus(id, fidIter->m_index);
@@ -255,6 +268,7 @@ public:
}
/// Guard for loading features from particular MWM by demand.
+ /// @note This guard is suitable when mwm is loaded.
class FeaturesLoaderGuard
{
public: