mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 03:43:52 +00:00
Change the worker to store the job using shared_ptr, so caller can still hold a reference to the job for other purpose
This commit is contained in:
@@ -170,7 +170,7 @@ bool BoostThreadWorker::wait_for_idle(unsigned timeout_ms)
|
|||||||
return !timeout_reached;
|
return !timeout_reached;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoostThreadWorker::push(std::unique_ptr<Job> job)
|
bool BoostThreadWorker::push(std::shared_ptr<Job> job)
|
||||||
{
|
{
|
||||||
if (!job)
|
if (!job)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class BoostThreadWorker : public Worker, private Job::Ctl
|
|||||||
{
|
{
|
||||||
struct JobEntry // Goes into worker and also out of worker as a finalize msg
|
struct JobEntry // Goes into worker and also out of worker as a finalize msg
|
||||||
{
|
{
|
||||||
std::unique_ptr<Job> job;
|
std::shared_ptr<Job> job;
|
||||||
bool canceled = false;
|
bool canceled = false;
|
||||||
std::exception_ptr eptr = nullptr;
|
std::exception_ptr eptr = nullptr;
|
||||||
};
|
};
|
||||||
@@ -110,7 +110,7 @@ public:
|
|||||||
BoostThreadWorker &operator=(const BoostThreadWorker &) = delete;
|
BoostThreadWorker &operator=(const BoostThreadWorker &) = delete;
|
||||||
BoostThreadWorker &operator=(BoostThreadWorker &&) = delete;
|
BoostThreadWorker &operator=(BoostThreadWorker &&) = delete;
|
||||||
|
|
||||||
bool push(std::unique_ptr<Job> job) override;
|
bool push(std::shared_ptr<Job> job) override;
|
||||||
|
|
||||||
bool is_idle() const override
|
bool is_idle() const override
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class PlaterWorker: public Worker {
|
|||||||
wxWindow *m_plater;
|
wxWindow *m_plater;
|
||||||
|
|
||||||
class PlaterJob : public Job {
|
class PlaterJob : public Job {
|
||||||
std::unique_ptr<Job> m_job;
|
std::shared_ptr<Job> m_job;
|
||||||
wxWindow *m_plater;
|
wxWindow *m_plater;
|
||||||
long long m_process_duration; // [ms]
|
long long m_process_duration; // [ms]
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ class PlaterWorker: public Worker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaterJob(wxWindow *p, std::unique_ptr<Job> j)
|
PlaterJob(wxWindow *p, std::shared_ptr<Job> j)
|
||||||
: m_job{std::move(j)}, m_plater{p}
|
: m_job{std::move(j)}, m_plater{p}
|
||||||
{
|
{
|
||||||
// TODO: decide if disabling slice button during UI job is what we
|
// TODO: decide if disabling slice button during UI job is what we
|
||||||
@@ -131,9 +131,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always package the job argument into a PlaterJob
|
// Always package the job argument into a PlaterJob
|
||||||
bool push(std::unique_ptr<Job> job) override
|
bool push(std::shared_ptr<Job> job) override
|
||||||
{
|
{
|
||||||
return m_w.push(std::make_unique<PlaterJob>(m_plater, std::move(job)));
|
return m_w.push(std::make_shared<PlaterJob>(m_plater, std::move(job)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_idle() const override { return m_w.is_idle(); }
|
bool is_idle() const override { return m_w.is_idle(); }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Worker {
|
|||||||
public:
|
public:
|
||||||
// Queue up a new job after the current one. This call does not block.
|
// Queue up a new job after the current one. This call does not block.
|
||||||
// Returns false if the job gets discarded.
|
// Returns false if the job gets discarded.
|
||||||
virtual bool push(std::unique_ptr<Job> job) = 0;
|
virtual bool push(std::shared_ptr<Job> job) = 0;
|
||||||
|
|
||||||
// Returns true if no job is running, the job queue is empty and no job
|
// Returns true if no job is running, the job queue is empty and no job
|
||||||
// message is left to be processed. This means that nothing is left to
|
// message is left to be processed. This means that nothing is left to
|
||||||
@@ -73,7 +73,7 @@ bool queue_job(Worker &w, ProcessFn fn, FinishFn finishfn)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto j = std::make_unique<LambdaJob>(std::move(fn), std::move(finishfn));
|
auto j = std::make_shared<LambdaJob>(std::move(fn), std::move(finishfn));
|
||||||
return w.push(std::move(j));
|
return w.push(std::move(j));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ bool queue_job(Worker &w, ProcessFn fn)
|
|||||||
return queue_job(w, std::move(fn), [](bool, std::exception_ptr &) {});
|
return queue_job(w, std::move(fn), [](bool, std::exception_ptr &) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool queue_job(Worker &w, std::unique_ptr<Job> j)
|
inline bool queue_job(Worker &w, std::shared_ptr<Job> j)
|
||||||
{
|
{
|
||||||
return w.push(std::move(j));
|
return w.push(std::move(j));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user