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

Remove useless class AbstractRepositoryManager

ItemRepositoryRegistry doesn't use AbstractRepositoryManager.
ItemRepository only forwards the manager to ItemRepositoryRegistry.
Therefore, these two classes don't need AbstractRepositoryManager.
Since AbstractRepositoryManager is not useful anywhere else either,
remove the entire class. 5128ac8d made
this abstract class useless by commenting out a single call to its
single member function:
     ~RepositoryManager() {
-      deleteRepository();
+      //Don't do this, we don't need it, and it may lead to crashes
+//       deleteRepository();
     }

No class inherits RepositoryManager, so it doesn't need a virtual
destructor.
parent f2687e5f
......@@ -12,6 +12,7 @@
#include "appendedlist_static.h"
#include "serialization/itemrepository.h"
#include "serialization/itemrepositoryreferencecounting.h"
#include <serialization/repositorymanager.h>
#include "util/kdevhash.h"
#include <debug.h>
......
......@@ -8,6 +8,7 @@
#include "identifier.h"
#include "serialization/itemrepository.h"
#include "serialization/itemrepositoryreferencecounting.h"
#include <serialization/repositorymanager.h>
#include "types/typeutils.h"
#include <typeinfo>
#include "types/typealiastype.h"
......
......@@ -14,6 +14,7 @@
#include "../types/typeregister.h"
#include <serialization/referencecounting.h>
#include <serialization/itemrepository.h>
#include <serialization/repositorymanager.h>
#define DEBUG_TYPE_REPOSITORY
#define ASSERT_ON_PROBLEM
......
......@@ -17,18 +17,4 @@ uint staticItemRepositoryVersion()
AbstractItemRepository::~AbstractItemRepository()
{
}
AbstractRepositoryManager::AbstractRepositoryManager()
{
}
AbstractRepositoryManager::~AbstractRepositoryManager()
{
}
void AbstractRepositoryManager::deleteRepository()
{
delete m_repository;
m_repository = nullptr;
}
}
......@@ -39,19 +39,6 @@ public:
/// unlock the repository
virtual void unlock() = 0;
};
/// Internal helper class that wraps around a repository object and manages its lifetime.
class KDEVPLATFORMSERIALIZATION_EXPORT AbstractRepositoryManager
{
public:
AbstractRepositoryManager();
virtual ~AbstractRepositoryManager();
void deleteRepository();
protected:
mutable AbstractItemRepository* m_repository = nullptr;
};
}
#endif // ABSTRACTITEMREPOSITORY_H
......@@ -9,6 +9,7 @@
#include "itemrepository.h"
#include "referencecounting.h"
#include "repositorymanager.h"
#include <utility>
......
......@@ -18,7 +18,6 @@
#include "referencecounting.h"
#include "abstractitemrepository.h"
#include "repositorymanager.h"
#include "itemrepositoryregistry.h"
//#define DEBUG_MONSTERBUCKETS
......@@ -1110,14 +1109,14 @@ public:
/// is triggered from within duchain, so you don't need to care about it.
explicit ItemRepository(const QString& repositoryName, Mutex* mutex,
ItemRepositoryRegistry* registry = &globalItemRepositoryRegistry(),
uint repositoryVersion = 1, AbstractRepositoryManager* manager = nullptr)
uint repositoryVersion = 1)
: m_repositoryName(repositoryName)
, m_repositoryVersion(repositoryVersion)
, m_mutex(mutex)
, m_registry(registry)
{
if (m_registry)
m_registry->registerRepository(this, manager);
m_registry->registerRepository(this);
}
~ItemRepository() override
......
......@@ -22,6 +22,8 @@
#include "debug.h"
#include <mutex>
#include <set>
#include <utility>
using namespace KDevelop;
......@@ -104,7 +106,8 @@ public:
bool m_shallDelete = false;
bool m_wasShutdown = false;
QString m_path;
QMap<AbstractItemRepository*, AbstractRepositoryManager*> m_repositories;
// TODO: is the order of repositories important? If not, store them in a QSet rather than std::set.
std::set<AbstractItemRepository*> m_repositories;
QMap<QString, QAtomicInt*> m_customCounters;
mutable QRecursiveMutex m_mutex;
......@@ -181,12 +184,12 @@ ItemRepositoryRegistry& globalItemRepositoryRegistry()
return *ItemRepositoryRegistry::self();
}
void ItemRepositoryRegistry::registerRepository(AbstractItemRepository* repository, AbstractRepositoryManager* manager)
void ItemRepositoryRegistry::registerRepository(AbstractItemRepository* repository)
{
Q_D(ItemRepositoryRegistry);
QMutexLocker lock(&d->m_mutex);
d->m_repositories.insert(repository, manager);
d->m_repositories.insert(repository);
if (!d->m_path.isEmpty()) {
// Locking the repository is documented as the caller's responsibility.
if (!repository->open(d->m_path)) {
......@@ -241,8 +244,8 @@ void ItemRepositoryRegistry::unRegisterRepository(AbstractItemRepository* reposi
Q_D(ItemRepositoryRegistry);
QMutexLocker lock(&d->m_mutex);
Q_ASSERT(d->m_repositories.contains(repository));
d->m_repositories.remove(repository);
Q_ASSERT(d->m_repositories.count(repository) == 1);
d->m_repositories.erase(repository);
}
//After calling this, the data-directory may be a new one
......@@ -292,8 +295,7 @@ void ItemRepositoryRegistry::store()
Q_D(ItemRepositoryRegistry);
QMutexLocker lock(&d->m_mutex);
for (auto it = d->m_repositories.constBegin(), end = d->m_repositories.constEnd(); it != end; ++it) {
auto* const repository = it.key();
for (auto* repository : std::as_const(d->m_repositories)) {
std::scoped_lock repoLock(*repository);
repository->store();
}
......@@ -326,8 +328,7 @@ void ItemRepositoryRegistry::printAllStatistics() const
Q_D(const ItemRepositoryRegistry);
QMutexLocker lock(&d->m_mutex);
for (auto it = d->m_repositories.constBegin(), end = d->m_repositories.constEnd(); it != end; ++it) {
AbstractItemRepository* repository = it.key();
for (auto* repository : std::as_const(d->m_repositories)) {
std::scoped_lock repoLock(*repository);
qCDebug(SERIALIZATION) << "statistics in" << repository->repositoryName() << ":";
qCDebug(SERIALIZATION) << repository->printStatistics();
......@@ -340,8 +341,7 @@ int ItemRepositoryRegistry::finalCleanup()
QMutexLocker lock(&d->m_mutex);
int changed = false;
for (auto it = d->m_repositories.constBegin(), end = d->m_repositories.constEnd(); it != end; ++it) {
AbstractItemRepository* repository = it.key();
for (auto* repository : std::as_const(d->m_repositories)) {
std::scoped_lock repoLock(*repository);
int added = repository->finalCleanup();
changed += added;
......@@ -355,8 +355,7 @@ ItemRepositoryRegistry::~ItemRepositoryRegistry()
{
Q_D(const ItemRepositoryRegistry);
for (auto it = d->m_repositories.cbegin(), end = d->m_repositories.cend(); it != end; ++it) {
auto* const repository = it.key();
for (auto* repository : std::as_const(d->m_repositories)) {
std::scoped_lock repoLock(*repository);
repository->close();
}
......
......@@ -17,7 +17,6 @@ class QAtomicInt;
namespace KDevelop {
class ISession;
class AbstractRepositoryManager;
class AbstractItemRepository;
class ItemRepositoryRegistryPrivate;
......@@ -48,7 +47,7 @@ public:
/// Add a new repository.
/// It will automatically be opened with the current path, if one is set.
/// @note A caller of this function, other than @p repository's constructor, must hold @p repository's mutex lock.
void registerRepository(AbstractItemRepository* repository, AbstractRepositoryManager* manager);
void registerRepository(AbstractItemRepository* repository);
/// Remove a repository.
/// @note Unregistering does not close @p repository.
......
......@@ -20,7 +20,6 @@ namespace KDevelop {
/// Especially it helps doing thread-safe lazy repository-creation.
template <class ItemRepositoryType, bool unloadingEnabled = true, bool lazy = true>
struct RepositoryManager
: public AbstractRepositoryManager
{
public:
using Mutex = std::decay_t<decltype(*std::declval<ItemRepositoryType>().mutex())>;
......@@ -37,8 +36,6 @@ public:
}
}
~RepositoryManager() override = default;
Q_DISABLE_COPY(RepositoryManager)
ItemRepositoryType * repository() const
......@@ -61,8 +58,7 @@ private:
if (!m_repository) {
QMutexLocker lock(&m_registry.mutex());
if (!m_repository) {
m_repository = new ItemRepositoryType(m_name, m_mutex, &m_registry, m_version,
const_cast<RepositoryManager*>(this));
m_repository = new ItemRepositoryType(m_name, m_mutex, &m_registry, m_version);
(*this)->setUnloadingEnabled(unloadingEnabled);
}
}
......@@ -72,6 +68,7 @@ private:
int m_version;
ItemRepositoryRegistry& m_registry;
Mutex* m_mutex;
mutable AbstractItemRepository* m_repository = nullptr;
};
}
......
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