Review fixes.

This commit is contained in:
Yuri Gorshenin 2015-04-27 17:24:08 +03:00 committed by Alex Zolotarev
parent 3cd1aabf37
commit d730b89b55
5 changed files with 28 additions and 25 deletions

View file

@ -47,10 +47,10 @@ bool Index::GetVersion(string const & name, MwmInfo & info) const
return true;
}
shared_ptr<MwmSet::MwmValueBase> Index::CreateValue(string const & name) const
MwmSet::TMwmValueBasePtr Index::CreateValue(string const & name) const
{
shared_ptr<MwmValue> p(new MwmValue(name));
ASSERT(p->GetHeader().IsMWMSuitable(), ());
TMwmValueBasePtr p(new MwmValue(name));
ASSERT(static_cast<MwmValue &>(*p.get()).GetHeader().IsMWMSuitable(), ());
return p;
}

View file

@ -38,7 +38,7 @@ class Index : public MwmSet
protected:
// MwmSet overrides:
bool GetVersion(string const & name, MwmInfo & info) const override;
shared_ptr<MwmValueBase> CreateValue(string const & name) const override;
TMwmValueBasePtr CreateValue(string const & name) const override;
void UpdateMwmInfo(MwmId id) override;
public:

View file

@ -22,9 +22,9 @@ namespace
return true;
}
shared_ptr<MwmValueBase> CreateValue(string const &) const override
TMwmValueBasePtr CreateValue(string const &) const override
{
return shared_ptr<MwmValueBase>(new MwmValue());
return TMwmValueBasePtr(new MwmValue());
}
public:

View file

@ -42,7 +42,7 @@ MwmSet::MwmLock::MwmLock(MwmSet & mwmSet, string const & fileName)
m_value = m_mwmSet->LockValueImpl(m_mwmId);
}
MwmSet::MwmLock::MwmLock(MwmSet & mwmSet, MwmId mwmId, shared_ptr<MwmValueBase> value)
MwmSet::MwmLock::MwmLock(MwmSet & mwmSet, MwmId mwmId, TMwmValueBasePtr value)
: m_mwmSet(&mwmSet), m_mwmId(mwmId), m_value(value)
{
}
@ -50,6 +50,7 @@ MwmSet::MwmLock::MwmLock(MwmSet & mwmSet, MwmId mwmId, shared_ptr<MwmValueBase>
MwmSet::MwmLock::MwmLock(MwmLock && lock)
: m_mwmSet(lock.m_mwmSet), m_mwmId(lock.m_mwmId), m_value(move(lock.m_value))
{
lock.m_mwmSet = nullptr;
lock.m_mwmId = MwmSet::INVALID_MWM_ID;
}
@ -243,17 +244,17 @@ MwmInfo const & MwmSet::GetMwmInfo(MwmId id) const
return m_info[id];
}
shared_ptr<MwmSet::MwmValueBase> MwmSet::LockValue(MwmId id)
MwmSet::TMwmValueBasePtr MwmSet::LockValue(MwmId id)
{
lock_guard<mutex> lock(m_lock);
return LockValueImpl(id);
}
shared_ptr<MwmSet::MwmValueBase> MwmSet::LockValueImpl(MwmId id)
MwmSet::TMwmValueBasePtr MwmSet::LockValueImpl(MwmId id)
{
ASSERT_LESS(id, m_info.size(), ());
if (id >= m_info.size())
return shared_ptr<MwmValueBase>();
return TMwmValueBasePtr();
UpdateMwmInfo(id);
if (!m_info[id].IsUpToDate())
@ -266,7 +267,7 @@ shared_ptr<MwmSet::MwmValueBase> MwmSet::LockValueImpl(MwmId id)
{
if (it->first == id)
{
shared_ptr<MwmValueBase> result = it->second;
TMwmValueBasePtr result = it->second;
m_cache.erase(it);
return result;
}
@ -274,17 +275,17 @@ shared_ptr<MwmSet::MwmValueBase> MwmSet::LockValueImpl(MwmId id)
return CreateValue(m_info[id].m_fileName);
}
void MwmSet::UnlockValue(MwmId id, shared_ptr<MwmValueBase> p)
void MwmSet::UnlockValue(MwmId id, TMwmValueBasePtr p)
{
lock_guard<mutex> lock(m_lock);
UnlockValueImpl(id, p);
}
void MwmSet::UnlockValueImpl(MwmId id, shared_ptr<MwmValueBase> p)
void MwmSet::UnlockValueImpl(MwmId id, TMwmValueBasePtr p)
{
ASSERT(p, (id));
ASSERT_LESS(id, m_info.size(), ());
if (id >= m_info.size() || !p.get())
if (id >= m_info.size() || p.get() == nullptr)
return;
ASSERT_GREATER(m_info[id].m_lockCount, 0, ());
@ -323,7 +324,7 @@ namespace
explicit MwmIdIsEqualTo(MwmSet::MwmId id) : m_id(id) {}
bool operator()(pair<MwmSet::MwmId, shared_ptr<MwmSet::MwmValueBase>> const & p) const
bool operator()(pair<MwmSet::MwmId, MwmSet::TMwmValueBasePtr> const & p) const
{
return p.first == m_id;
}

View file

@ -74,15 +74,17 @@ public:
virtual ~MwmValueBase() {}
};
using TMwmValueBasePtr = shared_ptr<MwmValueBase>;
// Mwm lock, which is used to lock mwm when its FileContainer is used.
class MwmLock
class MwmLock final
{
public:
MwmLock();
MwmLock(MwmSet & mwmSet, MwmId mwmId);
MwmLock(MwmSet & mwmSet, string const & fileName);
MwmLock(MwmLock && lock);
virtual ~MwmLock();
~MwmLock();
// Returns a non-owning ptr.
template <typename T>
@ -99,11 +101,11 @@ public:
private:
friend class MwmSet;
MwmLock(MwmSet & mwmSet, MwmId mwmId, shared_ptr<MwmValueBase> value);
MwmLock(MwmSet & mwmSet, MwmId mwmId, TMwmValueBasePtr value);
MwmSet * m_mwmSet;
MwmId m_mwmId;
shared_ptr<MwmValueBase> m_value;
TMwmValueBasePtr m_value;
NONCOPYABLE(MwmLock);
};
@ -161,17 +163,17 @@ protected:
/// @return True when it's possible to get file format version - in
/// this case version is set to the file format version.
virtual bool GetVersion(string const & name, MwmInfo & info) const = 0;
virtual shared_ptr<MwmValueBase> CreateValue(string const & name) const = 0;
virtual TMwmValueBasePtr CreateValue(string const & name) const = 0;
void Cleanup();
private:
typedef deque<pair<MwmId, shared_ptr<MwmValueBase>>> CacheType;
typedef deque<pair<MwmId, TMwmValueBasePtr>> CacheType;
shared_ptr<MwmValueBase> LockValue(MwmId id);
shared_ptr<MwmValueBase> LockValueImpl(MwmId id);
void UnlockValue(MwmId id, shared_ptr<MwmValueBase> p);
void UnlockValueImpl(MwmId id, shared_ptr<MwmValueBase> p);
TMwmValueBasePtr LockValue(MwmId id);
TMwmValueBasePtr LockValueImpl(MwmId id);
void UnlockValue(MwmId id, TMwmValueBasePtr p);
void UnlockValueImpl(MwmId id, TMwmValueBasePtr p);
/// Find first removed mwm or add a new one.
/// @precondition This function is always called under mutex m_lock.