Commit 62301743 authored by Igor Kushnir's avatar Igor Kushnir Committed by Milian Wolff
Browse files

Eliminate ItemRepositoryRegistryPrivate::open()

This function was called only from ItemRepositoryRegistry's constructor.
Move its implementation to ItemRepositoryRegistryPrivate() to make this
clear. Remove ItemRepositoryRegistryPrivate::m_mutex lock from
ItemRepositoryRegistryPrivate() because a constructor of a class doesn't
need to lock its own mutex.

Remove the `m_path == path` check from the constructor as at that point
m_path is empty and path is asserted to be non-empty.

Remove the code that opens contained repositories from the constructor
as m_repositories is always empty there.

Remove ItemRepositoryRegistryPrivate::m_owner. This data member is now
used only in the constructor, so there is no need to store it.
parent 188fdab5
......@@ -101,43 +101,29 @@ namespace KDevelop {
class ItemRepositoryRegistryPrivate
{
public:
ItemRepositoryRegistry* m_owner;
bool m_shallDelete;
bool m_wasShutdown;
bool m_shallDelete = false;
bool m_wasShutdown = false;
QString m_path;
QMap<AbstractItemRepository*, AbstractRepositoryManager*> m_repositories;
QMap<QString, QAtomicInt*> m_customCounters;
mutable QRecursiveMutex m_mutex;
explicit ItemRepositoryRegistryPrivate(ItemRepositoryRegistry* owner)
: m_owner(owner)
, m_shallDelete(false)
, m_wasShutdown(false)
{
}
/// @param path A shared directory-path that the item-repositories are to be loaded from.
/// @note Currently the given path must reference a hidden directory, just to make sure we're
/// not accidentally deleting something important.
explicit ItemRepositoryRegistryPrivate(ItemRepositoryRegistry& owner, const QString& path);
void lockForWriting();
void unlockForWriting();
void deleteDataDirectory(const QString& path, bool recreate = true);
/// @param path A shared directory-path that the item-repositories are to be loaded from.
/// @returns Whether the repository registry has been opened successfully.
/// If @c false, then all registered repositories should have been deleted.
/// @note Currently the given path must reference a hidden directory, just to make sure we're
/// not accidentally deleting something important.
bool open(const QString& path);
};
//The global item-repository registry
ItemRepositoryRegistry* ItemRepositoryRegistry::m_self = nullptr;
ItemRepositoryRegistry::ItemRepositoryRegistry(const QString& repositoryPath)
: d_ptr(new ItemRepositoryRegistryPrivate(this))
: d_ptr(new ItemRepositoryRegistryPrivate(*this, repositoryPath))
{
Q_D(ItemRepositoryRegistry);
Q_ASSERT(!repositoryPath.isEmpty());
d->open(repositoryPath);
}
void ItemRepositoryRegistry::initialize(const QString& repositoryPath)
......@@ -277,12 +263,9 @@ void ItemRepositoryRegistryPrivate::deleteDataDirectory(const QString& path, boo
}
}
bool ItemRepositoryRegistryPrivate::open(const QString& path)
ItemRepositoryRegistryPrivate::ItemRepositoryRegistryPrivate(ItemRepositoryRegistry& owner, const QString& path)
{
QMutexLocker mlock(&m_mutex);
if (m_path == path) {
return true;
}
Q_ASSERT(!path.isEmpty());
// Check if the repository shall be cleared
if (shouldClear(path)) {
......@@ -292,16 +275,6 @@ bool ItemRepositoryRegistryPrivate::open(const QString& path)
QDir().mkpath(path);
for (auto it = m_repositories.constBegin(), end = m_repositories.constEnd(); it != end; ++it) {
auto* const repository = it.key();
std::scoped_lock repoLock(*repository);
if (!repository->open(path)) {
deleteDataDirectory(path);
qCritical() << "failed to open a repository";
abort();
}
}
QFile f(path + QLatin1String("/Counters"));
if (f.open(QIODevice::ReadOnly)) {
QDataStream stream(&f);
......@@ -312,13 +285,11 @@ bool ItemRepositoryRegistryPrivate::open(const QString& path)
stream >> counterName;
int counterValue;
stream >> counterValue;
m_owner->customCounter(counterName, 0) = counterValue;
owner.customCounter(counterName, 0) = counterValue;
}
}
m_path = path;
return true;
}
void ItemRepositoryRegistry::store()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment