ConcurrentQueue: std::move jobs

Moving a std::function can be faster than copying it. Correcting these
normally minor inefficiencies is important here because they occur under
a mutex lock.
This commit is contained in:
Igor Kushnir 2021-03-16 14:27:59 +02:00 committed by Luis Ángel San Martín
parent d869e1230b
commit d8a6b7f432

View File

@ -8,6 +8,7 @@
#include <functional>
#include <condition_variable>
#include <queue>
#include <utility>
#include <vector>
namespace YACReader {
@ -40,7 +41,7 @@ public:
{
std::lock_guard<std::mutex> lock(queueMutex);
_queue.emplace(job);
_queue.emplace(std::move(job));
}
jobAvailableVar.notify_one();
@ -105,7 +106,7 @@ private:
return;
}
job = _queue.front();
job = std::move(_queue.front());
_queue.pop();
}