Commit 34112122 authored by Milian Wolff's avatar Milian Wolff
Browse files

Port declaration comment string repository to non-recursive mutex

Again, use locking on the outside here and disable internal locking.
parent 830a9aef
......@@ -54,11 +54,19 @@ DeclarationData::DeclarationData()
///@todo Use reference counting
static Repositories::StringRepository& commentRepository()
{
static auto mutex = QMutex(QMutex::Recursive);
static QMutex mutex;
static Repositories::StringRepository commentRepositoryObject(QStringLiteral("Comment Repository"), &mutex);
return commentRepositoryObject;
}
template <typename Op>
static auto commentRepositoryOp(Op&& op)
{
auto& repo = commentRepository();
QMutexLocker lock(repo.mutex());
return op(repo);
}
void initDeclarationRepositories()
{
commentRepository();
......@@ -167,22 +175,25 @@ QByteArray Declaration::comment() const
{
DUCHAIN_D(Declaration);
if (!d->m_comment)
return nullptr;
else
return Repositories::arrayFromItem(commentRepository().itemFromIndex(d->m_comment));
return QByteArray();
return commentRepositoryOp([d](const Repositories::StringRepository& repo) {
return Repositories::arrayFromItem(repo.itemFromIndex(d->m_comment));
});
}
void Declaration::setComment(const QByteArray& str)
{
DUCHAIN_D_DYNAMIC(Declaration);
if (str.isEmpty())
if (str.isEmpty()) {
d->m_comment = 0;
else
d->m_comment =
commentRepository().index(Repositories::StringRepositoryItemRequest(str.constData(),
IndexedString::hashString(str.constData(),
str.length()),
str.length()));
return;
}
const auto request = Repositories::StringRepositoryItemRequest(
str.constData(), IndexedString::hashString(str.constData(), str.length()), str.length());
d->m_comment = commentRepositoryOp([&](Repositories::StringRepository& repo) { return repo.index(request); });
}
void Declaration::setComment(const QString& str)
......
......@@ -93,7 +93,7 @@ struct StringRepositoryItemRequest
const char* m_text;
};
using StringRepository = ItemRepository<StringData, StringRepositoryItemRequest, false, true>;
using StringRepository = ItemRepository<StringData, StringRepositoryItemRequest, false, false>;
///@param item must be valid(nonzero)
inline QString stringFromItem(const StringData* item)
......
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