mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 23:25:59 +08:00
Clarify comments for thread safe queue
Cleanup
This commit is contained in:
parent
7eeffd6dca
commit
4298149e49
@ -21,19 +21,8 @@ class PlaterWorker: public Worker {
|
|||||||
WorkerSubclass m_w;
|
WorkerSubclass m_w;
|
||||||
Plater *m_plater;
|
Plater *m_plater;
|
||||||
|
|
||||||
struct JobHolder : Job {
|
|
||||||
std::unique_ptr<Job> m_job;
|
|
||||||
void process(Ctl &ctl) override { m_job->process(ctl); };
|
|
||||||
void finalize(bool canceled, std::exception_ptr &e) override
|
|
||||||
{
|
|
||||||
m_job->finalize(canceled, e);
|
|
||||||
}
|
|
||||||
JobHolder(std::unique_ptr<Job> &&j) : m_job{std::move(j)} {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class JobSubclass>
|
|
||||||
class PlaterJob : public Job {
|
class PlaterJob : public Job {
|
||||||
JobSubclass m_job;
|
std::unique_ptr<Job> m_job;
|
||||||
Plater *m_plater;
|
Plater *m_plater;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -64,12 +53,12 @@ class PlaterWorker: public Worker {
|
|||||||
} wctl{c};
|
} wctl{c};
|
||||||
|
|
||||||
CursorSetterRAII busycursor{wctl};
|
CursorSetterRAII busycursor{wctl};
|
||||||
m_job.process(wctl);
|
m_job->process(wctl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalize(bool canceled, std::exception_ptr &eptr) override
|
void finalize(bool canceled, std::exception_ptr &eptr) override
|
||||||
{
|
{
|
||||||
m_job.finalize(canceled, eptr);
|
m_job->finalize(canceled, eptr);
|
||||||
|
|
||||||
if (eptr) try {
|
if (eptr) try {
|
||||||
std::rethrow_exception(eptr);
|
std::rethrow_exception(eptr);
|
||||||
@ -79,9 +68,8 @@ class PlaterWorker: public Worker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class...Args>
|
PlaterJob(Plater *p, std::unique_ptr<Job> j)
|
||||||
PlaterJob(Plater *p, Args&&...args)
|
: m_job{std::move(j)}, m_plater{p}
|
||||||
: m_job{std::forward<Args>(args)...}, 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
|
||||||
// want.
|
// want.
|
||||||
@ -117,7 +105,7 @@ 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::unique_ptr<Job> job) override
|
||||||
{
|
{
|
||||||
return m_w.push(std::make_unique<PlaterJob<JobHolder>>(m_plater, std::move(job)));
|
return m_w.push(std::make_unique<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(); }
|
||||||
|
@ -9,14 +9,20 @@
|
|||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
// Helper structure for overloads of ThreadSafeQueueSPSC::consume_one()
|
||||||
|
// to block if the queue is empty.
|
||||||
struct BlockingWait
|
struct BlockingWait
|
||||||
{
|
{
|
||||||
|
// Timeout to wait for the arrival of new element into the queue.
|
||||||
unsigned timeout_ms = 0;
|
unsigned timeout_ms = 0;
|
||||||
|
|
||||||
|
// An optional atomic flag to set true if an incoming element gets
|
||||||
|
// consumed. The flag will be atomically set to true when popping the
|
||||||
|
// front of the queue.
|
||||||
std::atomic<bool> *pop_flag = nullptr;
|
std::atomic<bool> *pop_flag = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A thread safe queue for one producer and one consumer. Use consume_one_blk
|
// A thread safe queue for one producer and one consumer.
|
||||||
// to block on an empty queue.
|
|
||||||
template<class T,
|
template<class T,
|
||||||
template<class, class...> class Container = std::deque,
|
template<class, class...> class Container = std::deque,
|
||||||
class... ContainerArgs>
|
class... ContainerArgs>
|
||||||
@ -54,7 +60,8 @@ public:
|
|||||||
|
|
||||||
m_queue.pop();
|
m_queue.pop();
|
||||||
|
|
||||||
if (blkw.pop_flag) // The optional atomic is set before the lock us unlocked
|
if (blkw.pop_flag)
|
||||||
|
// The optional flag is set before the lock us unlocked.
|
||||||
blkw.pop_flag->store(true);
|
blkw.pop_flag->store(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user