diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-12-20 18:23:14 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-12-24 19:31:24 +0100 |
commit | e81df263f4123a39fe6d4d50fb21f47dd242e796 (patch) | |
tree | 4b8cd13da31ac3fb3a2d2695b65595d7c5570439 /spline | |
parent | 2613beb8028ecac53548d311b27ff38559763f6c (diff) |
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 <optional> in
compat/mutex.
Diffstat (limited to 'spline')
-rw-r--r-- | spline/spline.cpp | 19 | ||||
-rw-r--r-- | spline/spline.hpp | 29 |
2 files changed, 16 insertions, 32 deletions
diff --git a/spline/spline.cpp b/spline/spline.cpp index 752e85d1..9b0147a8 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -75,11 +75,6 @@ float spline::get_value(double x) float spline::get_value_no_save(double x) const { - return const_cast<spline&>(*this).get_value_no_save_internal(x); -} - -float spline::get_value_no_save_internal(double x) -{ QMutexLocker foo(&_mutex); float q = float(x * bucket_size_coefficient(points)); @@ -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<QPointF>& 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<double>()); } -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 <cstddef> #include <vector> @@ -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<QPointF>& 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<QPointF>& 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<spline_detail::settings> s; QMetaObject::Connection conn_changed, conn_maxx, conn_maxy; + mutable std::vector<float> data = std::vector<float>(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<float> data = std::vector<float>(value_count, float(-16)); - - mutex _mutex { mutex::recursive }; - QPointF last_input_value; std::shared_ptr<QObject> ctx { std::make_shared<QObject>() }; - 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<spline_detail::base_settings> get_settings() override; std::shared_ptr<const spline_detail::base_settings> get_settings() const override; |