1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Do not hammer the CPU if there are no jobs.

This commit is contained in:
Sandu Liviu Catalin 2020-09-06 21:30:44 +03:00
parent cc69b15190
commit 97fe1101e3
2 changed files with 6 additions and 1 deletions

View File

@ -366,7 +366,11 @@ void Worker::Work()
// Try to get a job from the queue // Try to get a job from the queue
if (!m_PendingJobs.try_dequeue(job)) if (!m_PendingJobs.try_dequeue(job))
{ {
return; // No jobs using namespace std::chrono_literals;
// Do not hammer the CPU if there are no jobs
std::this_thread::sleep_for(50ms);
// Try again
return;
} }
// Identify the job type // Identify the job type
switch (job->mType) switch (job->mType)

View File

@ -9,6 +9,7 @@
#include <mutex> #include <mutex>
#include <atomic> #include <atomic>
#include <vector> #include <vector>
#include <chrono>
#include <condition_variable> #include <condition_variable>
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------