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
{
public:
explicit ConcurrentQueue(int threadCount)
explicit ConcurrentQueue(std::size_t threadCount)
: jobsLeft(0),
bailout(false)
{
threads = std::vector<std::thread>(threadCount);
for (int index = 0; index < threadCount; ++index) {
threads[index] = std::thread([this] {
this->nextJob();
});
}
threads.reserve(threadCount);
for (; threadCount != 0; --threadCount)
threads.emplace_back(&ConcurrentQueue::nextJob, this);
}
~ConcurrentQueue()