mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -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:
parent
d869e1230b
commit
d8a6b7f432
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user