Skip to content

Commit

Permalink
fix #5428
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Jan 14, 2017
1 parent 2aa5a1f commit 5a97ea9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions rts/System/Threading/ThreadPool.cpp
Expand Up @@ -120,7 +120,7 @@ static bool DoTask(int tid)
if (idx == 0)
NotifyWorkerThreads(true);

const spring_time dt = tg->ExecuteLoop();
const spring_time dt = tg->ExecuteLoop(false);

threadStats[tid].numTasks += 1;
threadStats[tid].sumTime += dt.toNanoSecsi();
Expand All @@ -133,7 +133,7 @@ static bool DoTask(int tid)
#else
while (queue.try_dequeue(tg)) {
#endif
const spring_time dt = tg->ExecuteLoop();
const spring_time dt = tg->ExecuteLoop(false);

threadStats[tid].numTasks += 1;
threadStats[tid].sumTime += dt.toNanoSecsi();
Expand Down Expand Up @@ -194,7 +194,7 @@ void WaitForFinished(std::shared_ptr<ITaskGroup>&& taskGroup)

assert(!taskGroup->IsSingleTask());
assert(!taskGroup->SelfDelete());
taskGroup->ExecuteLoop();
taskGroup->ExecuteLoop(true);
}

// NOTE:
Expand Down
10 changes: 6 additions & 4 deletions rts/System/Threading/ThreadPool.h
Expand Up @@ -99,16 +99,18 @@ class ITaskGroup
virtual bool ExecuteStep() = 0;
virtual bool SelfDelete() const { return false; }

spring_time ExecuteLoop() {
spring_time ExecuteLoop(bool wffCall) {
const spring_time t0 = spring_now();

while (ExecuteStep());

const spring_time t1 = spring_now();
const spring_time dt = t1 - t0;

assert(inTaskQueue.load() == 1);
inTaskQueue.store(0);
if (!wffCall) {
assert(inTaskQueue.load() == 1);
inTaskQueue.store(0);
}

if (SelfDelete())
delete this;
Expand Down Expand Up @@ -577,7 +579,7 @@ static inline auto parallel_reduce(F&& f, G&& g) -> typename std::result_of<F()>
results[0] = std::move(tasks[0]->GetFuture());

// first job usually wants to run on the main thread
tasks[0]->ExecuteLoop();
tasks[0]->ExecuteLoop(false);

// need to push N individual tasks; see NOTE in TParallelTaskGroup
for (size_t i = 1; i < results.size(); ++i) {
Expand Down

0 comments on commit 5a97ea9

Please sign in to comment.