Close m_container on cross_mwm_routing.

This commit is contained in:
Lev Dragunov 2015-10-14 13:27:13 +03:00
parent 7af71e98ef
commit faf802173c
4 changed files with 26 additions and 15 deletions

View file

@ -370,13 +370,13 @@ private:
bool OsrmRouter::CheckRoutingAbility(m2::PointD const & startPoint, m2::PointD const & finalPoint,
TCountryFileFn const & countryFileFn, Index * index)
{
RoutingIndexManager manager(countryFileFn, index);
RoutingIndexManager manager(countryFileFn, *index);
return manager.GetMappingByPoint(startPoint)->IsValid() &&
manager.GetMappingByPoint(finalPoint)->IsValid();
}
OsrmRouter::OsrmRouter(Index * index, TCountryFileFn const & countryFileFn)
: m_pIndex(index), m_indexManager(countryFileFn, index)
: m_pIndex(index), m_indexManager(countryFileFn, *index)
{
}

View file

@ -47,17 +47,15 @@ bool CheckMwmConsistency(LocalCountryFile const & localFile)
namespace routing
{
RoutingMapping::RoutingMapping(string const & countryFile, MwmSet * pIndex)
RoutingMapping::RoutingMapping(string const & countryFile, MwmSet & index)
: m_mapCounter(0),
m_facadeCounter(0),
m_crossContextLoaded(0),
m_countryFile(countryFile),
m_error(IRouter::ResultCode::RouteFileNotExist),
m_pIndex(pIndex)
m_pIndex(&index)
{
CHECK(m_pIndex != nullptr, ());
m_handle = pIndex->GetMwmHandleByCountryFile(CountryFile(countryFile));
m_handle = index.GetMwmHandleByCountryFile(CountryFile(countryFile));
if (!m_handle.IsAlive())
return;
@ -86,13 +84,19 @@ void RoutingMapping::LoadFileIfNeeded()
{
ASSERT(m_pIndex != nullptr, ());
if (!m_handle.IsAlive() && m_mwmId.IsAlive())
{
m_handle = m_pIndex->GetMwmHandleById(m_mwmId);
m_container.Open(m_mwmId.GetInfo()->GetLocalFile().GetPath(MapOptions::CarRouting));
}
}
void RoutingMapping::FreeFileIfPossible()
{
if (m_handle.IsAlive() && m_mapCounter == 0 && m_facadeCounter == 0)
if (m_mapCounter == 0 && m_facadeCounter == 0 && m_handle.IsAlive())
{
m_handle = MwmSet::MwmHandle();
m_container.Close();
}
}
RoutingMapping::~RoutingMapping()
@ -106,6 +110,8 @@ RoutingMapping::~RoutingMapping()
void RoutingMapping::Map()
{
LoadFileIfNeeded();
if (!m_handle.IsAlive())
return;
++m_mapCounter;
if (!m_segMapping.IsMapped())
{
@ -127,6 +133,8 @@ void RoutingMapping::LoadFacade()
if (!m_facadeCounter)
{
LoadFileIfNeeded();
if (!m_handle.IsAlive())
return;
m_dataFacade.Load(m_container);
}
++m_facadeCounter;
@ -149,6 +157,9 @@ void RoutingMapping::LoadCrossContext()
LoadFileIfNeeded();
if (!m_handle.IsAlive())
return;
if (m_container.IsExist(ROUTING_CROSS_CONTEXT_TAG))
{
m_crossContext.Load(m_container.GetReader(ROUTING_CROSS_CONTEXT_TAG));
@ -160,6 +171,7 @@ void RoutingMapping::FreeCrossContext()
{
m_crossContextLoaded = false;
m_crossContext = CrossRoutingContextReader();
FreeFileIfPossible();
}
TRoutingMappingPtr RoutingIndexManager::GetMappingByPoint(m2::PointD const & point)

View file

@ -27,7 +27,7 @@ struct RoutingMapping
/// @postcondition IsValid() == false.
RoutingMapping() : m_pIndex(nullptr) {}
/// @param countryFile Country file name without extension.
RoutingMapping(string const & countryFile, MwmSet * pIndex);
RoutingMapping(string const & countryFile, MwmSet & index);
~RoutingMapping();
void Map();
@ -39,7 +39,7 @@ struct RoutingMapping
void LoadCrossContext();
void FreeCrossContext();
bool IsValid() const { return m_mwmId.IsAlive() && m_error == IRouter::ResultCode::NoError; }
bool IsValid() const { return m_error == IRouter::ResultCode::NoError && m_mwmId.IsAlive(); }
IRouter::ResultCode GetError() const { return m_error; }
@ -97,10 +97,9 @@ public:
class RoutingIndexManager
{
public:
RoutingIndexManager(TCountryFileFn const & countryFileFn, MwmSet * index)
RoutingIndexManager(TCountryFileFn const & countryFileFn, MwmSet & index)
: m_countryFileFn(countryFileFn), m_index(index)
{
ASSERT(index, ());
}
TRoutingMappingPtr GetMappingByPoint(m2::PointD const & point);
@ -118,7 +117,7 @@ public:
private:
TCountryFileFn m_countryFileFn;
unordered_map<string, TRoutingMappingPtr> m_mapping;
MwmSet * m_index;
MwmSet & m_index;
};
} // namespace routing

View file

@ -70,7 +70,7 @@ UNIT_TEST(RoutingMappingCountryFileLockTest)
{
LocalFileGenerator generator("1TestCountry");
{
RoutingMapping testMapping(generator.GetCountryName(), (&generator.GetMwmSet()));
RoutingMapping testMapping(generator.GetCountryName(), (generator.GetMwmSet()));
TEST(testMapping.IsValid(), ());
TEST_EQUAL(generator.GetNumRefs(), 1, ());
}
@ -83,7 +83,7 @@ UNIT_TEST(IndexManagerLockManagementTest)
string const fileName("1TestCountry");
LocalFileGenerator generator(fileName);
RoutingIndexManager manager([&fileName](m2::PointD const & q) { return fileName; },
&generator.GetMwmSet());
generator.GetMwmSet());
{
auto testMapping = manager.GetMappingByName(fileName);
TEST(testMapping->IsValid(), ());