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. --- spline/spline.cpp | 19 ++++--------------- spline/spline.hpp | 29 ++++++++++++----------------- 2 files changed, 16 insertions(+), 32 deletions(-) (limited to 'spline') diff --git a/spline/spline.cpp b/spline/spline.cpp index 752e85d1..9b0147a8 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -74,11 +74,6 @@ float spline::get_value(double x) } float spline::get_value_no_save(double x) const -{ - return const_cast(*this).get_value_no_save_internal(x); -} - -float spline::get_value_no_save_internal(double x) { QMutexLocker foo(&_mutex); @@ -98,7 +93,7 @@ bool spline::get_last_value(QPointF& point) return activep; } -float spline::get_value_internal(int x) +float spline::get_value_internal(int x) const { if (!validp) { @@ -112,12 +107,6 @@ float spline::get_value_internal(int x) return sign * clamp(ret_, 0, 1000); } -void spline::add_lone_point() -{ - points = { QPointF(s->opts.clamp_x_, s->opts.clamp_y_) }; - s->points = points; -} - QPointF spline::ensure_in_bounds(const QList& points, int i) { const int sz = points.size(); @@ -148,7 +137,7 @@ bool spline::sort_fn(const QPointF& one, const QPointF& two) return one.x() < two.x(); } -void spline::update_interp_data() +void spline::update_interp_data() const { points_t list = points; ensure_valid(list); @@ -208,7 +197,7 @@ void spline::update_interp_data() }; // multiplier helps fill in all the x's needed - const unsigned end = int(c_interp * (p2_x - p1_x)) + 1; + const unsigned end{int(c_interp * (p2_x - p1_x)) + 1u}; for (unsigned k = 0; k <= end; k++) { @@ -363,7 +352,7 @@ double spline::max_output() const return std::fabs(clamp.to()); } -void spline::ensure_valid(points_t& list) +void spline::ensure_valid(points_t& list) const { QMutexLocker foo(&_mutex); diff --git a/spline/spline.hpp b/spline/spline.hpp index 3d2d6e57..acac2ad7 100644 --- a/spline/spline.hpp +++ b/spline/spline.hpp @@ -8,12 +8,10 @@ #pragma once -#include "compat/copyable-mutex.hpp" #include "options/options.hpp" - #include "axis-opts.hpp" - #include "export.hpp" +#include "compat/copyable-mutex.hpp" #include #include @@ -95,10 +93,8 @@ struct OTR_SPLINE_EXPORT base_spline : base_spline_, spline_modify_mixin, spline class OTR_SPLINE_EXPORT spline : public base_spline { double bucket_size_coefficient(const QList& points) const; - void update_interp_data(); - float get_value_internal(int x); - void add_lone_point(); - float get_value_no_save_internal(double x); + void update_interp_data() const; + float get_value_internal(int x) const; static bool sort_fn(const QPointF& one, const QPointF& two); static QPointF ensure_in_bounds(const QList& points, int i); @@ -106,21 +102,20 @@ class OTR_SPLINE_EXPORT spline : public base_spline void disconnect_signals(); + mutex _mutex { mutex::Recursive }; std::shared_ptr s; QMetaObject::Connection conn_changed, conn_maxx, conn_maxy; + mutable std::vector data = std::vector(value_count, float(-16)); + mutable QPointF last_input_value; + mutable bool activep = false; + mutable bool validp = false; - static constexpr inline std::size_t value_count = 4096; - - std::vector data = std::vector(value_count, float(-16)); - - mutex _mutex { mutex::recursive }; - QPointF last_input_value; std::shared_ptr ctx { std::make_shared() }; - bool activep = false; - bool validp = false; + // cached s->points + mutable points_t points; - points_t points; + static constexpr inline std::size_t value_count = 4096; public: void invalidate_settings(); @@ -153,7 +148,7 @@ public: void set_tracking_active(bool value) override; bundle get_bundle(); - void ensure_valid(points_t& in_out); + void ensure_valid(points_t& in_out) const; std::shared_ptr get_settings() override; std::shared_ptr get_settings() const override; -- cgit v1.2.3