Simplify the Job Queue:

This is a refactor aimed at cleaning up and simplifying the existing
job queue.

As of now, all jobs are cancelled at the same time and in the same
way, so this commit removes the per-job cancellation token. If the
need for such support is demonstrated, support can be re-added.

* Revise documentation for ClosureCounter and Workers.
* Simplify code, removing unnecessary function arguments and
  deduplicating expressions
* Restructure job handlers to no longer need to pass a job's
  handle to the job.
This commit is contained in:
John Freeman
2021-11-16 10:55:52 -06:00
committed by Nik Bougalis
parent df02eb125f
commit c2a08a1f26
31 changed files with 164 additions and 242 deletions

View File

@@ -36,10 +36,8 @@ Job::Job(
std::string const& name,
std::uint64_t index,
LoadMonitor& lm,
std::function<void(Job&)> const& job,
CancelCallback cancelCallback)
: m_cancelCallback(cancelCallback)
, mType(type)
std::function<void()> const& job)
: mType(type)
, mJobIndex(index)
, mJob(job)
, mName(name)
@@ -54,27 +52,12 @@ Job::getType() const
return mType;
}
Job::CancelCallback
Job::getCancelCallback() const
{
assert(m_cancelCallback);
return m_cancelCallback;
}
Job::clock_type::time_point const&
Job::queue_time() const
{
return m_queue_time;
}
bool
Job::shouldCancel() const
{
if (m_cancelCallback)
return m_cancelCallback();
return false;
}
void
Job::doJob()
{
@@ -82,19 +65,13 @@ Job::doJob()
m_loadEvent->start();
m_loadEvent->setName(mName);
mJob(*this);
mJob();
// Destroy the lambda, otherwise we won't include
// its duration in the time measurement
mJob = nullptr;
}
void
Job::rename(std::string const& newName)
{
mName = newName;
}
bool
Job::operator>(const Job& j) const
{