Skip to content

Commit

Permalink
Slightly more interesting example
Browse files Browse the repository at this point in the history
  • Loading branch information
delscorcho committed Dec 3, 2018
1 parent 0e71b55 commit fdc779f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions jobsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ namespace jobsystem
{
if (candidate.m_state->AwaitingCancellation())
{
job.m_state->SetDone();
candidate.m_state->SetDone();
jobIter = queue.erase(jobIter);

continue;
Expand Down Expand Up @@ -598,7 +598,7 @@ namespace jobsystem

case eJobEvent_JobStart:
{
auto& timeline = workerIndex < m_workers.size() ? m_timelines[workerIndex] : m_timelines[m_workers.size()];
ProfilingTimeline& timeline = workerIndex < m_workers.size() ? m_timelines[workerIndex] : m_timelines[m_workers.size()];
ProfilingTimeline::TimelineEntry entry;
entry.jobId = jobId;
entry.start = ProfileClock::now();
Expand All @@ -609,8 +609,8 @@ namespace jobsystem

case eJobEvent_JobDone:
{
auto& timeline = workerIndex < m_workers.size() ? m_timelines[workerIndex] : m_timelines[m_workers.size()];
auto& entry = timeline.m_entries.back();
ProfilingTimeline& timeline = workerIndex < m_workers.size() ? m_timelines[workerIndex] : m_timelines[m_workers.size()];
ProfilingTimeline::TimelineEntry& entry = timeline.m_entries.back();
entry.end = ProfileClock::now();
}
break;
Expand Down Expand Up @@ -691,6 +691,9 @@ namespace jobsystem
{
JobStatePtr state = nullptr;

// \todo - workers should maintain a tls pointer to themselves, so we can push
// directly into our own queue.

if (!m_workers.empty())
{
// Add round-robin style. Note that work-stealing helps load-balance,
Expand Down Expand Up @@ -812,8 +815,8 @@ namespace jobsystem
std::atomic<unsigned int> m_jobsRun; ///< Counter to track # of jobs run.
std::atomic<unsigned int> m_jobsAssisted; ///< Counter to track # of jobs run via external Assist*().
std::atomic<unsigned int> m_jobsStolen; ///< Counter to track # of jobs stolen from another worker's queue.
std::atomic<uint64_t> m_usedMask; ///< Mask with bits set according to the IDs of the jobs that have executed jobs.
std::atomic<uint64_t> m_awokenMask; ///< Mask with bits set according to the IDs of the jobs that have been awoken at least once.
std::atomic<affinity_t> m_usedMask; ///< Mask with bits set according to the IDs of the jobs that have executed jobs.
std::atomic<affinity_t> m_awokenMask; ///< Mask with bits set according to the IDs of the jobs that have been awoken at least once.

private:

Expand Down Expand Up @@ -867,7 +870,7 @@ namespace jobsystem

for (size_t workerIndex = 0; workerIndex < workerCount + 1; ++workerIndex)
{
auto& timeline = m_timelines[workerIndex];
ProfilingTimeline& timeline = m_timelines[workerIndex];

const char* name = (workerIndex < workerCount) ? m_workers[workerIndex]->m_desc.m_name.c_str() : "[Assist]";

Expand All @@ -886,7 +889,7 @@ namespace jobsystem
buffer[bufferSize - 2] = '\n';
buffer[bufferSize - 1] = 0;

for (auto& entry : timeline.m_entries)
for (ProfilingTimeline::TimelineEntry& entry : timeline.m_entries)
{
auto startNs = std::chrono::duration_cast<std::chrono::nanoseconds>(entry.start - m_firstJobTime).count();
auto endNs = std::chrono::duration_cast<std::chrono::nanoseconds>(entry.end - m_firstJobTime).count();
Expand Down Expand Up @@ -1090,11 +1093,16 @@ namespace jobsystem

JobChainBuilder& Go()
{
if (m_allJobs.empty())
{
return *this;
}

Then();
Do([]() {}, 'J');
m_joinJob = m_allJobs.back();

for (auto job : m_allJobs)
for (JobStatePtr& job : m_allJobs)
{
job->SetReady();
}
Expand All @@ -1104,11 +1112,12 @@ namespace jobsystem

void Fail()
{
for (auto job : m_allJobs)
for (JobStatePtr& job : m_allJobs)
{
job->Cancel();
}

m_allJobs.clear();
m_failed = true;
}

Expand All @@ -1119,7 +1128,10 @@ namespace jobsystem

void WaitForAll()
{
m_joinJob->Wait();
if (m_joinJob)
{
m_joinJob->Wait();
}
}

void AssistAndWaitForAll()
Expand Down
Binary file modified test/jobsystemtest/jobsystemtest.cpp
Binary file not shown.
Binary file modified test/jobsystemtest/x64/Release/jobsystemtest.exe
Binary file not shown.

0 comments on commit fdc779f

Please sign in to comment.