From e81df263f4123a39fe6d4d50fb21f47dd242e796 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 20 Dec 2018 18:23:14 +0100 Subject: remove const correctness violations This is possibly related to a livelock where several threads do const removal in their respective code paths. Use the `mutable' specifier for the mutexes and spline's cached data. Now using the `mutable' specifier, get rid of in compat/mutex. --- options/bundle.cpp | 12 ++---------- options/bundle.hpp | 15 ++++----------- 2 files changed, 6 insertions(+), 21 deletions(-) (limited to 'options') diff --git a/options/bundle.cpp b/options/bundle.cpp index 8db4f906..938639b3 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -20,15 +20,7 @@ using namespace options::globals; namespace options::detail { -mutex::mutex(QMutex::RecursionMode mode) : QMutex(mode) {} - -mutex::operator QMutex*() const -{ - return const_cast(static_cast(this)); -} - bundle::bundle(const QString& group_name) : - mtx(QMutex::Recursive), group_name(group_name), saved(group_name), transient(saved) @@ -82,13 +74,13 @@ void bundle::store_kv(const QString& name, const QVariant& new_value) QVariant bundle::get_variant(const QString& name) const { - QMutexLocker l(mtx); + QMutexLocker l(&mtx); return transient.get_variant(name); } bool bundle::contains(const QString &name) const { - QMutexLocker l(mtx); + QMutexLocker l(&mtx); return transient.contains(name); } diff --git a/options/bundle.hpp b/options/bundle.hpp index 9ab7f74c..4c2b9781 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -29,13 +29,6 @@ #include "export.hpp" namespace options::detail { - class OTR_OPTIONS_EXPORT mutex final : public QMutex - { - public: - explicit mutex(QMutex::RecursionMode mode); - cc_noinline operator QMutex*() const; // NOLINT - }; - class bundle; } // ns options::detail @@ -51,7 +44,7 @@ class OTR_OPTIONS_EXPORT bundle final : public QObject, public connector { Q_OBJECT - mutex mtx; + mutable QMutex mtx { QMutex::Recursive }; const QString group_name; group saved; group transient; @@ -65,7 +58,7 @@ public: bundle(const bundle&) = delete; bundle& operator=(const bundle&) = delete; - QMutex* get_mtx() const override { return mtx; } + QMutex* get_mtx() const override { return &mtx; } QString name() const { return group_name; } explicit bundle(const QString& group_name); @@ -100,8 +93,8 @@ private: friend OTR_OPTIONS_EXPORT std::shared_ptr options::make_bundle(const QString& name); - [[nodiscard]] std::shared_ptr make_bundle_(const k& key); - [[nodiscard]] static bundler& bundler_singleton(); + std::shared_ptr make_bundle_(const k& key); + static bundler& bundler_singleton(); bundler(); ~bundler(); -- cgit v1.2.3