mirror of
https://github.com/YACReader/yacreader
synced 2025-09-19 19:54:37 -04:00
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:
committed by
Luis Ángel San Martín
parent
d869e1230b
commit
d8a6b7f432
@ -8,6 +8,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace YACReader {
|
namespace YACReader {
|
||||||
@ -40,7 +41,7 @@ public:
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(queueMutex);
|
std::lock_guard<std::mutex> lock(queueMutex);
|
||||||
_queue.emplace(job);
|
_queue.emplace(std::move(job));
|
||||||
}
|
}
|
||||||
|
|
||||||
jobAvailableVar.notify_one();
|
jobAvailableVar.notify_one();
|
||||||
@ -105,7 +106,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
job = _queue.front();
|
job = std::move(_queue.front());
|
||||||
_queue.pop();
|
_queue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user