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:
authorvng <viktor.govako@gmail.com>2015-09-25 16:09:20 +0300
committervng <viktor.govako@gmail.com>2015-09-25 17:17:51 +0300
commitc56f4c20b946bf62831e917a695d4e6c7861fdd9 (patch)
treed98919a12647ac1d6e8365a60896aa4744ac12f4
parent7629852c751575bec7f407e2aab4fa4f3c2cde8a (diff)
[mwm set] Do not create MwmHandle instantly after registering map.
-rw-r--r--generator/routing_generator.cpp2
-rw-r--r--indexer/index.cpp2
-rw-r--r--indexer/index.hpp2
-rw-r--r--indexer/indexer_tests/index_test.cpp6
-rw-r--r--indexer/indexer_tests/mwm_set_test.cpp2
-rw-r--r--indexer/mwm_set.cpp12
-rw-r--r--indexer/mwm_set.hpp4
-rw-r--r--map/feature_vec_model.cpp17
-rw-r--r--map/feature_vec_model.hpp2
-rw-r--r--map/framework.cpp16
-rw-r--r--map/framework.hpp2
-rw-r--r--map/mwm_tests/mwm_index_test.cpp7
-rw-r--r--routing/routing_tests/routing_mapping_test.cpp12
-rw-r--r--search/integration_tests/retrieval_test.cpp30
-rw-r--r--search/search_tests/locality_finder_test.cpp6
15 files changed, 63 insertions, 59 deletions
diff --git a/generator/routing_generator.cpp b/generator/routing_generator.cpp
index a699e4110f..aa3d39b178 100644
--- a/generator/routing_generator.cpp
+++ b/generator/routing_generator.cpp
@@ -272,7 +272,7 @@ void BuildRoutingIndex(string const & baseDir, string const & countryName, strin
}
FeatureType ft;
- Index::FeaturesLoaderGuard loader(index, p.first.GetId());
+ Index::FeaturesLoaderGuard loader(index, p.first);
loader.GetFeatureByIndex(fID, ft);
ft.ParseGeometry(FeatureType::BEST_GEOMETRY);
diff --git a/indexer/index.cpp b/indexer/index.cpp
index 508e0306c0..1592715dff 100644
--- a/indexer/index.cpp
+++ b/indexer/index.cpp
@@ -63,7 +63,7 @@ unique_ptr<MwmSet::MwmValueBase> Index::CreateValue(MwmInfo & info) const
return unique_ptr<MwmSet::MwmValueBase>(move(p));
}
-pair<MwmSet::MwmHandle, MwmSet::RegResult> Index::RegisterMap(LocalCountryFile const & localFile)
+pair<MwmSet::MwmId, MwmSet::RegResult> Index::RegisterMap(LocalCountryFile const & localFile)
{
auto result = Register(localFile);
if (result.first.IsAlive() && result.second == MwmSet::RegResult::Success)
diff --git a/indexer/index.hpp b/indexer/index.hpp
index 44057132dd..eab3b90c79 100644
--- a/indexer/index.hpp
+++ b/indexer/index.hpp
@@ -75,7 +75,7 @@ public:
/// Registers a new map.
- WARN_UNUSED_RESULT pair<MwmHandle, RegResult> RegisterMap(
+ WARN_UNUSED_RESULT pair<MwmId, RegResult> RegisterMap(
platform::LocalCountryFile const & localFile);
/// Deregisters a map from internal records.
diff --git a/indexer/indexer_tests/index_test.cpp b/indexer/indexer_tests/index_test.cpp
index 7c5f5a2332..1b30199d23 100644
--- a/indexer/indexer_tests/index_test.cpp
+++ b/indexer/indexer_tests/index_test.cpp
@@ -113,7 +113,7 @@ UNIT_TEST(Index_MwmStatusNotifications)
TEST(p.first.IsAlive(), ());
TEST_EQUAL(MwmSet::RegResult::Success, p.second, ());
observer.CheckExpectations();
- localFileV1Id = p.first.GetId();
+ localFileV1Id = p.first;
}
// Checks that map can't registered twice.
@@ -122,7 +122,7 @@ UNIT_TEST(Index_MwmStatusNotifications)
TEST(p.first.IsAlive(), ());
TEST_EQUAL(MwmSet::RegResult::VersionAlreadyExists, p.second, ());
observer.CheckExpectations();
- TEST_EQUAL(localFileV1Id, p.first.GetId(), ());
+ TEST_EQUAL(localFileV1Id, p.first, ());
}
// Checks that observers are notified when map is updated.
@@ -134,7 +134,7 @@ UNIT_TEST(Index_MwmStatusNotifications)
TEST(p.first.IsAlive(), ());
TEST_EQUAL(MwmSet::RegResult::Success, p.second, ());
observer.CheckExpectations();
- localFileV2Id = p.first.GetId();
+ localFileV2Id = p.first;
TEST_NOT_EQUAL(localFileV1Id, localFileV2Id, ());
}
diff --git a/indexer/indexer_tests/mwm_set_test.cpp b/indexer/indexer_tests/mwm_set_test.cpp
index 76c25c9867..372bab619e 100644
--- a/indexer/indexer_tests/mwm_set_test.cpp
+++ b/indexer/indexer_tests/mwm_set_test.cpp
@@ -133,7 +133,7 @@ UNIT_TEST(MwmSetLockAndIdTest)
{
auto p = mwmSet.Register(LocalCountryFile::MakeForTesting("4"));
- MwmSet::MwmHandle const & handle = p.first;
+ MwmSet::MwmHandle handle = mwmSet.GetMwmHandleById(p.first);
TEST(handle.IsAlive(), ());
TEST_EQUAL(MwmSet::RegResult::Success, p.second, ("Can't register test mwm 4"));
TEST_EQUAL(MwmInfo::STATUS_REGISTERED, handle.GetInfo()->GetStatus(), ());
diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp
index e5ee51cd01..71d8bcef0e 100644
--- a/indexer/mwm_set.cpp
+++ b/indexer/mwm_set.cpp
@@ -83,7 +83,7 @@ MwmSet::MwmId MwmSet::GetMwmIdByCountryFileImpl(CountryFile const & countryFile)
return MwmId(it->second.back());
}
-pair<MwmSet::MwmHandle, MwmSet::RegResult> MwmSet::Register(LocalCountryFile const & localFile)
+pair<MwmSet::MwmId, MwmSet::RegResult> MwmSet::Register(LocalCountryFile const & localFile)
{
lock_guard<mutex> lock(m_lock);
@@ -108,26 +108,26 @@ pair<MwmSet::MwmHandle, MwmSet::RegResult> MwmSet::Register(LocalCountryFile con
LOG(LINFO, ("Updating already registered mwm:", name));
info->SetStatus(MwmInfo::STATUS_REGISTERED);
info->m_file = localFile;
- return make_pair(GetLock(id), RegResult::VersionAlreadyExists);
+ return make_pair(id, RegResult::VersionAlreadyExists);
}
LOG(LWARNING, ("Trying to add too old (", localFile.GetVersion(), ") mwm (", name,
"), current version:", info->GetVersion()));
- return make_pair(MwmHandle(), RegResult::VersionTooOld);
+ return make_pair(MwmId(), RegResult::VersionTooOld);
}
-pair<MwmSet::MwmHandle, MwmSet::RegResult> MwmSet::RegisterImpl(LocalCountryFile const & localFile)
+pair<MwmSet::MwmId, MwmSet::RegResult> MwmSet::RegisterImpl(LocalCountryFile const & localFile)
{
// This function can throw an exception for a bad mwm file.
shared_ptr<MwmInfo> info(CreateInfo(localFile));
if (!info)
- return make_pair(MwmHandle(), RegResult::UnsupportedFileFormat);
+ return make_pair(MwmId(), RegResult::UnsupportedFileFormat);
info->m_file = localFile;
info->SetStatus(MwmInfo::STATUS_REGISTERED);
m_info[localFile.GetCountryName()].push_back(info);
- return make_pair(GetLock(MwmId(info)), RegResult::Success);
+ return make_pair(MwmId(info), RegResult::Success);
}
bool MwmSet::DeregisterImpl(MwmId const & id)
diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp
index fb705ce7de..fb847e5f10 100644
--- a/indexer/mwm_set.hpp
+++ b/indexer/mwm_set.hpp
@@ -164,11 +164,11 @@ public:
/// are older than the localFile (in this case mwm handle will point
/// to just-registered file).
protected:
- WARN_UNUSED_RESULT pair<MwmHandle, RegResult> RegisterImpl(
+ WARN_UNUSED_RESULT pair<MwmId, RegResult> RegisterImpl(
platform::LocalCountryFile const & localFile);
public:
- WARN_UNUSED_RESULT pair<MwmHandle, RegResult> Register(
+ WARN_UNUSED_RESULT pair<MwmId, RegResult> Register(
platform::LocalCountryFile const & localFile);
//@}
diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp
index f28c8e65e1..65812a5c54 100644
--- a/map/feature_vec_model.cpp
+++ b/map/feature_vec_model.cpp
@@ -44,7 +44,7 @@ void FeaturesFetcher::InitClassificator()
}
}
-pair<MwmSet::MwmHandle, MwmSet::RegResult> FeaturesFetcher::RegisterMap(
+pair<MwmSet::MwmId, MwmSet::RegResult> FeaturesFetcher::RegisterMap(
LocalCountryFile const & localFile)
{
try
@@ -54,17 +54,20 @@ pair<MwmSet::MwmHandle, MwmSet::RegResult> FeaturesFetcher::RegisterMap(
{
LOG(LWARNING, ("Can't add map", localFile.GetCountryName(),
"Probably it's already added or has newer data version."));
- return result;
}
- MwmSet::MwmHandle & handle = result.first;
- ASSERT(handle.IsAlive(), ("Mwm lock invariant violation."));
- m_rect.Add(handle.GetInfo()->m_limitRect);
+ else
+ {
+ MwmSet::MwmId const & id = result.first;
+ ASSERT(id.IsAlive(), ());
+ m_rect.Add(id.GetInfo()->m_limitRect);
+ }
+
return result;
}
catch (RootException const & ex)
{
- LOG(LERROR, ("IO error while adding ", localFile.GetCountryName(), " map. ", ex.Msg()));
- return make_pair(MwmSet::MwmHandle(), MwmSet::RegResult::BadFile);
+ LOG(LERROR, ("IO error while adding", localFile.GetCountryName(), "map.", ex.Msg()));
+ return make_pair(MwmSet::MwmId(), MwmSet::RegResult::BadFile);
}
}
diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp
index f7e21a575a..fce5e8b0e4 100644
--- a/map/feature_vec_model.hpp
+++ b/map/feature_vec_model.hpp
@@ -46,7 +46,7 @@ class FeaturesFetcher : public Index::Observer
}
/// Registers a new map.
- WARN_UNUSED_RESULT pair<MwmSet::MwmHandle, MwmSet::RegResult> RegisterMap(
+ WARN_UNUSED_RESULT pair<MwmSet::MwmId, MwmSet::RegResult> RegisterMap(
platform::LocalCountryFile const & localFile);
/// Deregisters a map denoted by file from internal records.
diff --git a/map/framework.cpp b/map/framework.cpp
index 844be1328d..2667c8172a 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -102,7 +102,7 @@ namespace
char const kRouterTypeKey[] = "router";
}
-pair<MwmSet::MwmHandle, MwmSet::RegResult> Framework::RegisterMap(
+pair<MwmSet::MwmId, MwmSet::RegResult> Framework::RegisterMap(
LocalCountryFile const & localFile)
{
LOG(LINFO, ("Loading map:", localFile.GetCountryName()));
@@ -447,10 +447,10 @@ void Framework::UpdateLatestCountryFile(LocalCountryFile const & localFile)
return;
// Add downloaded map.
- auto result = m_model.RegisterMap(localFile);
- MwmSet::MwmHandle const & handle = result.first;
- if (handle.IsAlive())
- InvalidateRect(handle.GetInfo()->m_limitRect, true /* doForceUpdate */);
+ auto p = m_model.RegisterMap(localFile);
+ MwmSet::MwmId const & id = p.first;
+ if (id.IsAlive())
+ InvalidateRect(id.GetInfo()->m_limitRect, true /* doForceUpdate */);
GetSearchEngine()->ClearViewportsCache();
}
@@ -479,9 +479,9 @@ void Framework::RegisterAllMaps()
if (p.second != MwmSet::RegResult::Success)
continue;
- MwmSet::MwmHandle const & handle = p.first;
- ASSERT(handle.IsAlive(), ());
- minFormat = min(minFormat, static_cast<int>(handle.GetInfo()->m_version.format));
+ MwmSet::MwmId const & id = p.first;
+ ASSERT(id.IsAlive(), ());
+ minFormat = min(minFormat, static_cast<int>(id.GetInfo()->m_version.format));
}
m_countryTree.Init(maps);
diff --git a/map/framework.hpp b/map/framework.hpp
index 0fd1caecf4..06f972ffaf 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -203,7 +203,7 @@ public:
void DeregisterAllMaps();
/// Registers a local map file in internal indexes.
- pair<MwmSet::MwmHandle, MwmSet::RegResult> RegisterMap(
+ pair<MwmSet::MwmId, MwmSet::RegResult> RegisterMap(
platform::LocalCountryFile const & localFile);
//@}
diff --git a/map/mwm_tests/mwm_index_test.cpp b/map/mwm_tests/mwm_index_test.cpp
index f2ec06de68..3b299b4d95 100644
--- a/map/mwm_tests/mwm_index_test.cpp
+++ b/map/mwm_tests/mwm_index_test.cpp
@@ -42,10 +42,11 @@ bool RunTest(string const & countryFileName, int lowS, int highS)
auto p = src.RegisterMap(platform::LocalCountryFile::MakeForTesting(countryFileName));
if (p.second != MwmSet::RegResult::Success)
return false;
- MwmSet::MwmHandle const & handle = p.first;
- ASSERT(handle.IsAlive(), ());
- version::Format const version = handle.GetInfo()->m_version.format;
+ MwmSet::MwmId const & id = p.first;
+ ASSERT(id.IsAlive(), ());
+
+ version::Format const version = id.GetInfo()->m_version.format;
if (version == version::unknownFormat)
return false;
diff --git a/routing/routing_tests/routing_mapping_test.cpp b/routing/routing_tests/routing_mapping_test.cpp
index 57cdcb7674..7d4c977250 100644
--- a/routing/routing_tests/routing_mapping_test.cpp
+++ b/routing/routing_tests/routing_mapping_test.cpp
@@ -63,7 +63,7 @@ private:
ScopedFile m_testRoutingFile;
LocalCountryFile m_localFile;
TestMwmSet m_testSet;
- pair<MwmSet::MwmHandle, MwmSet::RegResult> m_result;
+ pair<MwmSet::MwmId, MwmSet::RegResult> m_result;
};
UNIT_TEST(RoutingMappingCountryFileLockTest)
@@ -72,10 +72,10 @@ UNIT_TEST(RoutingMappingCountryFileLockTest)
{
RoutingMapping testMapping(generator.GetCountryName(), (&generator.GetMwmSet()));
TEST(testMapping.IsValid(), ());
- TEST_EQUAL(generator.GetNumRefs(), 2, ());
+ TEST_EQUAL(generator.GetNumRefs(), 1, ());
}
// Routing mapping must unlock the file after destruction.
- TEST_EQUAL(generator.GetNumRefs(), 1, ());
+ TEST_EQUAL(generator.GetNumRefs(), 0, ());
}
UNIT_TEST(IndexManagerLockManagementTest)
@@ -87,13 +87,13 @@ UNIT_TEST(IndexManagerLockManagementTest)
{
auto testMapping = manager.GetMappingByName(fileName);
TEST(testMapping->IsValid(), ());
- TEST_EQUAL(generator.GetNumRefs(), 2, ());
+ TEST_EQUAL(generator.GetNumRefs(), 1, ());
}
// We freed mapping, but it still persists inside the manager cache.
- TEST_EQUAL(generator.GetNumRefs(), 2, ());
+ TEST_EQUAL(generator.GetNumRefs(), 1, ());
// Test cache clearing.
manager.Clear();
- TEST_EQUAL(generator.GetNumRefs(), 1, ());
+ TEST_EQUAL(generator.GetNumRefs(), 0, ());
}
} // namespace
diff --git a/search/integration_tests/retrieval_test.cpp b/search/integration_tests/retrieval_test.cpp
index 2a6f3d3dab..25ef9f9002 100644
--- a/search/integration_tests/retrieval_test.cpp
+++ b/search/integration_tests/retrieval_test.cpp
@@ -108,8 +108,8 @@ UNIT_TEST(Retrieval_Smoke)
Index index;
auto p = index.RegisterMap(file);
- auto & handle = p.first;
- TEST(handle.IsAlive(), ());
+ auto & id = p.first;
+ TEST(id.IsAlive(), ());
TEST_EQUAL(p.second, MwmSet::RegResult::Success, ());
search::SearchQueryParams params;
@@ -122,7 +122,7 @@ UNIT_TEST(Retrieval_Smoke)
// Retrieve all (100) whiskey bars from the mwm.
{
- TestCallback callback(handle.GetId());
+ TestCallback callback(id);
retrieval.Init(index, infos, m2::RectD(m2::PointD(0, 0), m2::PointD(1, 1)), params,
search::Retrieval::Limits());
@@ -130,14 +130,14 @@ UNIT_TEST(Retrieval_Smoke)
TEST(callback.WasTriggered(), ());
TEST_EQUAL(100, callback.Offsets().size(), ());
- TestCallback dummyCallback(handle.GetId());
+ TestCallback dummyCallback(id);
retrieval.Go(dummyCallback);
TEST(!dummyCallback.WasTriggered(), ());
}
// Retrieve all whiskey bars from the left-bottom 5 x 5 square.
{
- TestCallback callback(handle.GetId());
+ TestCallback callback(id);
search::Retrieval::Limits limits;
limits.SetMaxViewportScale(9.0);
@@ -150,7 +150,7 @@ UNIT_TEST(Retrieval_Smoke)
// Retrieve exactly 8 whiskey bars from the center.
{
- TestCallback callback(handle.GetId());
+ TestCallback callback(id);
search::Retrieval::Limits limits;
limits.SetMaxNumFeatures(8);
@@ -192,17 +192,17 @@ UNIT_TEST(Retrieval_3Mwms)
Index index;
auto mskP = index.RegisterMap(msk);
- auto & mskHandle = mskP.first;
+ auto & mskId = mskP.first;
auto mtvP = index.RegisterMap(mtv);
- auto & mtvHandle = mtvP.first;
+ auto & mtvId = mtvP.first;
auto zrhP = index.RegisterMap(zrh);
- auto & zrhHandle = zrhP.first;
+ auto & zrhId = zrhP.first;
- TEST(mskHandle.IsAlive(), ());
- TEST(mtvHandle.IsAlive(), ());
- TEST(zrhHandle.IsAlive(), ());
+ TEST(mskId.IsAlive(), ());
+ TEST(mtvId.IsAlive(), ());
+ TEST(zrhId.IsAlive(), ());
search::SearchQueryParams params;
InitParams("mtv", params);
@@ -213,7 +213,7 @@ UNIT_TEST(Retrieval_3Mwms)
search::Retrieval retrieval;
{
- TestCallback callback(mskHandle.GetId());
+ TestCallback callback(mskId);
search::Retrieval::Limits limits;
limits.SetMaxNumFeatures(1);
@@ -225,7 +225,7 @@ UNIT_TEST(Retrieval_3Mwms)
}
{
- MultiMwmCallback callback({mskHandle.GetId(), mtvHandle.GetId(), zrhHandle.GetId()});
+ MultiMwmCallback callback({mskId, mtvId, zrhId});
search::Retrieval::Limits limits;
limits.SetMaxNumFeatures(10 /* more than total number of features in all these mwms */);
@@ -237,7 +237,7 @@ UNIT_TEST(Retrieval_3Mwms)
}
{
- MultiMwmCallback callback({mskHandle.GetId(), mtvHandle.GetId(), zrhHandle.GetId()});
+ MultiMwmCallback callback({mskId, mtvId, zrhId});
search::Retrieval::Limits limits;
retrieval.Init(index, infos, m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(1.0, 1.0)), params,
diff --git a/search/search_tests/locality_finder_test.cpp b/search/search_tests/locality_finder_test.cpp
index 48314862ae..bcb50e6227 100644
--- a/search/search_tests/locality_finder_test.cpp
+++ b/search/search_tests/locality_finder_test.cpp
@@ -59,10 +59,10 @@ UNIT_TEST(LocalityFinder)
auto const p = index.Register(world);
TEST_EQUAL(MwmSet::RegResult::Success, p.second, ());
- MwmSet::MwmHandle const & handle = p.first;
- TEST(handle.IsAlive(), ());
+ MwmSet::MwmId const & id = p.first;
+ TEST(id.IsAlive(), ());
- rect = handle.GetId().GetInfo()->m_limitRect;
+ rect = id.GetInfo()->m_limitRect;
}
catch (RootException const & ex)
{