mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 15:41:58 +08:00
Add comments, remove some redundant template fiddling
Also make ThreadSafeQueueSPSC not copyable and non movable
This commit is contained in:
parent
155b152637
commit
7975dfab26
@ -67,6 +67,11 @@ class BoostThreadWorker : public Worker, private Job::Ctl
|
||||
void deliver(BoostThreadWorker &runner);
|
||||
};
|
||||
|
||||
// The m_running state flag needs special attention. Previously, it was set simply in the run()
|
||||
// method whenever a new job was taken from the input queue and unset after the finalize message
|
||||
// was pushed into the output queue. This was not correct. It must not be possible to consume
|
||||
// the finalize message before the flag gets unset, these two operations must be done atomically
|
||||
// So the underlying queues are here extended to support handling of this m_running flag.
|
||||
template<class El>
|
||||
class RawQueue: public std::deque<El> {
|
||||
std::atomic<bool> *m_running_ptr;
|
||||
@ -79,6 +84,7 @@ class BoostThreadWorker : public Worker, private Job::Ctl
|
||||
void set_stopped() { m_running_ptr->store(false); }
|
||||
};
|
||||
|
||||
// The running flag is set if a job is popped from the queue
|
||||
template<class El>
|
||||
class RawJobQueue: public RawQueue<El> {
|
||||
public:
|
||||
@ -90,6 +96,7 @@ class BoostThreadWorker : public Worker, private Job::Ctl
|
||||
}
|
||||
};
|
||||
|
||||
// The running flag is unset when the finalize message is pushed into the queue
|
||||
template<class El>
|
||||
class RawMsgQueue: public RawQueue<El> {
|
||||
public:
|
||||
|
@ -21,10 +21,6 @@ struct BlockingWait
|
||||
unsigned timeout_ms = 0;
|
||||
};
|
||||
|
||||
template<class T, class... Args>
|
||||
using NonSpecialMembersOnly = std::enable_if_t<
|
||||
(sizeof...(Args) >= 1) && !(... || std::is_convertible_v<Args, T>)>;
|
||||
|
||||
// A thread safe queue for one producer and one consumer.
|
||||
template<class T,
|
||||
template<class, class...> class Container = std::deque,
|
||||
@ -36,15 +32,16 @@ class ThreadSafeQueueSPSC
|
||||
std::condition_variable m_cond_var;
|
||||
|
||||
public:
|
||||
template<class...Qargs, class = NonSpecialMembersOnly<ThreadSafeQueueSPSC, Qargs...>>
|
||||
|
||||
// Forward arguments to the underlying queue
|
||||
template<class...Qargs>
|
||||
ThreadSafeQueueSPSC(Qargs &&...qargs)
|
||||
: m_queue{Container<T, ContainerArgs...>{std::forward<Qargs>(qargs)...}} {}
|
||||
|
||||
ThreadSafeQueueSPSC() = default;
|
||||
ThreadSafeQueueSPSC(const ThreadSafeQueueSPSC&) = default;
|
||||
ThreadSafeQueueSPSC(ThreadSafeQueueSPSC&&) = default;
|
||||
ThreadSafeQueueSPSC& operator=(const ThreadSafeQueueSPSC&) = default;
|
||||
ThreadSafeQueueSPSC& operator=(ThreadSafeQueueSPSC &&) = default;
|
||||
ThreadSafeQueueSPSC(const ThreadSafeQueueSPSC&) = delete;
|
||||
ThreadSafeQueueSPSC(ThreadSafeQueueSPSC&&) = delete;
|
||||
ThreadSafeQueueSPSC& operator=(const ThreadSafeQueueSPSC&) = delete;
|
||||
ThreadSafeQueueSPSC& operator=(ThreadSafeQueueSPSC &&) = delete;
|
||||
|
||||
// Consume one element, block if the queue is empty.
|
||||
template<class Fn>
|
||||
|
Loading…
x
Reference in New Issue
Block a user