check of stop thread without lambda
This commit is contained in:
parent
2c6f57cc5c
commit
a0983276b4
3 changed files with 8 additions and 11 deletions
|
@ -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<EmbossData> input, StopCondition is_stop)
|
||||
void EmbossJob::process(std::unique_ptr<EmbossData> input)
|
||||
{
|
||||
// Changing cursor to busy
|
||||
wxBeginBusyCursor();
|
||||
|
@ -37,7 +37,7 @@ void EmbossJob::process(std::unique_ptr<EmbossData> 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<EmbossData> input, StopCondition is_stop
|
|||
Emboss::ProjectScale project(std::move(projectZ), scale);
|
||||
auto its = std::make_unique<indexed_triangle_set>(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;
|
||||
|
|
|
@ -27,7 +27,7 @@ struct EmbossData
|
|||
class EmbossJob : public StopableJob<EmbossData>
|
||||
{
|
||||
protected:
|
||||
void process(std::unique_ptr<EmbossData> input, StopCondition is_stop) override;
|
||||
void process(std::unique_ptr<EmbossData> input) override;
|
||||
};
|
||||
|
||||
} // namespace Slic3r::GUI
|
||||
|
|
|
@ -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<bool(void)>;
|
||||
// Ability to stop processing developer must add check is_stopping() into process()
|
||||
template<typename TIn> class StopableJob
|
||||
{
|
||||
std::mutex m_mutex;
|
||||
|
@ -63,11 +61,10 @@ protected:
|
|||
|
||||
/// <summary>
|
||||
/// Thread job of processing input data
|
||||
/// Note: Use check function is_stoping(), when true than interupt processing
|
||||
/// </summary>
|
||||
/// <param name="input">input data to process</param>
|
||||
/// <param name="stop_condition">When lambda is true, quit processing,
|
||||
/// keep in mind check is under mutex so do it occasionally</param>
|
||||
virtual void process(std::unique_ptr<TIn> input, StopCondition stop_condition) = 0;
|
||||
virtual void process(std::unique_ptr<TIn> input) = 0;
|
||||
};
|
||||
|
||||
//////
|
||||
|
@ -107,7 +104,7 @@ void StopableJob<TIn>::run(std::unique_ptr<TIn> input)
|
|||
m_thread = std::thread(
|
||||
[this](std::unique_ptr<TIn> input) {
|
||||
do {
|
||||
process(std::move(input), [this]() { return is_stoping(); });
|
||||
process(std::move(input));
|
||||
|
||||
std::lock_guard lg(m_mutex);
|
||||
m_stop = false;
|
||||
|
|
Loading…
Reference in a new issue