From a0983276b4935b63f5316f2ad34c074ec902c3f6 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Thu, 25 Nov 2021 16:34:49 +0100 Subject: [PATCH] check of stop thread without lambda --- src/slic3r/GUI/Jobs/EmbossJob.cpp | 6 +++--- src/slic3r/GUI/Jobs/EmbossJob.hpp | 2 +- src/slic3r/GUI/Jobs/StopableJob.hpp | 11 ++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index ade70b831e..0f75d88bb6 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -17,7 +17,7 @@ namespace Priv { static void finalize(const EmbossData &input, const indexed_triangle_set &result); } // namespace Priv -void EmbossJob::process(std::unique_ptr input, StopCondition is_stop) +void EmbossJob::process(std::unique_ptr input) { // Changing cursor to busy wxBeginBusyCursor(); @@ -37,7 +37,7 @@ void EmbossJob::process(std::unique_ptr input, StopCondition is_stop const FontProp &prop = cfg.font_prop; ExPolygons shapes = Emboss::text2shapes(*input->font, text.c_str(), prop); - if (is_stop()) return; + if (is_stoping()) return; // exist 2d shape made by text ? // (no shape means that font hasn't any of text symbols) @@ -48,7 +48,7 @@ void EmbossJob::process(std::unique_ptr input, StopCondition is_stop Emboss::ProjectScale project(std::move(projectZ), scale); auto its = std::make_unique(Emboss::polygons2model(shapes, project)); - if (is_stop()) return; + if (is_stoping()) return; // for sure that some object is created from shape if (its->indices.empty()) return; diff --git a/src/slic3r/GUI/Jobs/EmbossJob.hpp b/src/slic3r/GUI/Jobs/EmbossJob.hpp index 72b9c568c3..392c657e6d 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.hpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.hpp @@ -27,7 +27,7 @@ struct EmbossData class EmbossJob : public StopableJob { protected: - void process(std::unique_ptr input, StopCondition is_stop) override; + void process(std::unique_ptr input) override; }; } // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Jobs/StopableJob.hpp b/src/slic3r/GUI/Jobs/StopableJob.hpp index 4a30445eda..2900a17b36 100644 --- a/src/slic3r/GUI/Jobs/StopableJob.hpp +++ b/src/slic3r/GUI/Jobs/StopableJob.hpp @@ -8,10 +8,8 @@ namespace Slic3r::GUI { // inspired by Job.hpp -// All public function can be call only from UI thread // Mechanism to stack processing and do only last one -// Ability to stop processing developer must add check into m_func -using StopCondition = std::function; +// Ability to stop processing developer must add check is_stopping() into process() template class StopableJob { std::mutex m_mutex; @@ -63,11 +61,10 @@ protected: /// /// Thread job of processing input data + /// Note: Use check function is_stoping(), when true than interupt processing /// /// input data to process - /// When lambda is true, quit processing, - /// keep in mind check is under mutex so do it occasionally - virtual void process(std::unique_ptr input, StopCondition stop_condition) = 0; + virtual void process(std::unique_ptr input) = 0; }; ////// @@ -107,7 +104,7 @@ void StopableJob::run(std::unique_ptr input) m_thread = std::thread( [this](std::unique_ptr input) { do { - process(std::move(input), [this]() { return is_stoping(); }); + process(std::move(input)); std::lock_guard lg(m_mutex); m_stop = false;