Skip to content

Commit

Permalink
fixed raise condition in taskscheduler_new
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwoop committed Apr 22, 2015
1 parent 1e423b1 commit 1d2cee2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 9 additions & 8 deletions common/tasking/taskscheduler_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace embree

TaskSchedulerNew::TaskSchedulerNew(size_t numThreads, bool spinning)
: threadCounter(numThreads), createThreads(true), terminate(false), anyTasksRunning(0), active(false), spinning(spinning),
task_set_function(nullptr)
task_set_function(nullptr), masterThread(0,this)
{
for (size_t i=0; i<MAX_THREADS; i++)
threadLocal[i] = NULL;
Expand Down Expand Up @@ -317,7 +317,7 @@ namespace embree
if (executeTaskSet(thread))
continue;
#endif

/* work on available task */
steal_loop(thread,
[&] () { return anyTasksRunning > 0; },
Expand Down Expand Up @@ -407,26 +407,27 @@ namespace embree
for (size_t i=0; i<workingThreads; i++)
{
const size_t otherThreadIndex = thread_task_size[i].second;
if (!threadLocal[otherThreadIndex])
Thread* othread = threadLocal[otherThreadIndex];
if (!othread)
continue;

if (threadLocal[otherThreadIndex]->tasks.steal(thread))
if (othread->tasks.steal(thread))
return true;
}
/* nothing found this time, do another round */

#else
for (size_t i=1; i<threadCount; i++)
//for (size_t i=1; i<32; i++)
{
__pause_cpu(32);
size_t otherThreadIndex = threadIndex+i;
if (otherThreadIndex >= threadCount) otherThreadIndex -= threadCount;

if (!threadLocal[otherThreadIndex])
Thread* othread = threadLocal[otherThreadIndex];
if (!othread)
continue;
if (threadLocal[otherThreadIndex]->tasks.steal(thread))

if (othread->tasks.steal(thread))
return true;
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions common/tasking/taskscheduler_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace embree

assert(!active);
active = true;
Thread thread(0,this);
Thread& thread = masterThread;
threadLocal[0] = &thread;
setThread(&thread);
thread.tasks.push_right(thread,size,closure);
Expand Down Expand Up @@ -274,7 +274,7 @@ namespace embree

assert(!active);
active = true;
Thread thread(0,this);
Thread& thread = masterThread;
threadLocal[0] = &thread;
setThread(&thread);

Expand Down Expand Up @@ -376,6 +376,7 @@ namespace embree
__dllexport2 static TaskSchedulerNew* global_instance();

private:
Thread masterThread;
static TaskSchedulerNew* g_instance;
static __thread Thread* thread_local_thread;

Expand Down

0 comments on commit 1d2cee2

Please sign in to comment.