diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-08-20 23:51:16 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-08-20 23:52:03 +0200 |
commit | 57a1091dfb2c6403cbe63c7ddca8acc7e3d0f940 (patch) | |
tree | a997ed523a853d9d5fff7d5b90b12a180b00a231 /competition/job.cpp | |
parent | f0b6d1b9c46578183b427bcec4bbe99ab10c7b97 (diff) |
Diffstat (limited to 'competition/job.cpp')
-rw-r--r-- | competition/job.cpp | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/competition/job.cpp b/competition/job.cpp deleted file mode 100644 index 043074e..0000000 --- a/competition/job.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include <chrono> -#include <cassert> -#include "job.h" - -void Scheduler::workerEntry() { - while (true) { - Job *job = nullptr; - - { - lock_guard commMutGuard(commMut); - if (terminateFlag) break; - if (jobs.size() > 0) { - job = jobs.front(); - jobs.pop(); - } - } - - if (job) { - job->callback(); - } else { - this_thread::sleep_for(chrono::milliseconds(100)); - } - } -} - -Scheduler::Scheduler(int nthreads) - : nthreads(nthreads) { - - assert(nthreads > 0); - - workers.reserve(nthreads); - for (int i = 0; i < nthreads; i++) { - workers.emplace_back([this]() { workerEntry(); }); - } -} - -Scheduler::~Scheduler() { - finish(); -} - -void Scheduler::submit(const function<void()> &func) { - Job *job = new Job(func); - lock_guard commMutGuard(commMut); - jobs.push(job); -} - -void Scheduler::finish() { - for (int i = 0; i < nthreads; i++) { - workers[i].join(); - } -} |