ConcurrentQueue: simplify the constructor implementation

* threadCount argument: int => std::size_t to avoid implicit casting;
* eliminate temporary empty std::thread objects;
* replace a trivial lambda with a function pointer and its argument;
* get rid of the unused dedicated loop counter.
This commit is contained in:
Igor Kushnir
2021-03-18 08:30:05 +02:00
committed by Luis Ángel San Martín
parent c333fbc7d0
commit 2655613543

View File

@ -14,16 +14,13 @@ namespace YACReader {
class ConcurrentQueue class ConcurrentQueue
{ {
public: public:
explicit ConcurrentQueue(int threadCount) explicit ConcurrentQueue(std::size_t threadCount)
: jobsLeft(0), : jobsLeft(0),
bailout(false) bailout(false)
{ {
threads = std::vector<std::thread>(threadCount); threads.reserve(threadCount);
for (int index = 0; index < threadCount; ++index) { for (; threadCount != 0; --threadCount)
threads[index] = std::thread([this] { threads.emplace_back(&ConcurrentQueue::nextJob, this);
this->nextJob();
});
}
} }
~ConcurrentQueue() ~ConcurrentQueue()