Skip to content

Commit ab080b3

Browse files
committed
Better threading communication
1 parent 4e12aaf commit ab080b3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Dataflow/Engine/Controller/NetworkEditorController.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,20 @@ void NetworkEditorController::executeGeneric(const ExecutableLookup* lookup, Mod
373373
}
374374

375375
ExecutionQueueManager::ExecutionQueueManager(ExecutionStrategyHandle& currentExecutor) : contexts_(1), currentExecutor_(currentExecutor),
376-
executionLaunchThread_([this]() {executeTopContext(); } )
376+
executionLaunchThread_([this]() {executeTopContext(); } ),
377+
executionMutex_("executionQueue"),
378+
somethingToExecute_("executionQueue")
377379
{
378380
}
379381

380382
void ExecutionQueueManager::enqueueContext(ExecutionContextHandle context)
381383
{
384+
Guard g(executionMutex_.get());
382385
if (contexts_.push(context))
386+
{
383387
std::cout << "ctx queued" << std::endl;
388+
somethingToExecute_.conditionBroadcast();
389+
}
384390
else
385391
std::cout << "ctx queue is full" << std::endl;
386392
}
@@ -389,9 +395,12 @@ void ExecutionQueueManager::executeTopContext()
389395
{
390396
while (true)
391397
{
392-
if (contexts_.read_available())
393-
contexts_.consume_one([&](ExecutionContextHandle ctx) { currentExecutor_->execute(*ctx); });
394-
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
398+
UniqueLock lock(executionMutex_.get());
399+
while (0 == contexts_.read_available())
400+
{
401+
somethingToExecute_.wait(lock);
402+
}
403+
contexts_.consume_one([&](ExecutionContextHandle ctx) { currentExecutor_->execute(*ctx); });
395404
}
396405
}
397406

src/Dataflow/Engine/Scheduler/ExecutionStrategy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <Dataflow/Engine/Scheduler/SchedulerInterfaces.h>
3333
#include <Dataflow/Engine/Scheduler/DynamicExecutor/WorkQueue.h>
3434
#include <boost/thread.hpp>
35+
#include <Core/Thread/ConditionVariable.h>
3536
#include <Dataflow/Engine/Scheduler/share.h>
3637

3738
namespace SCIRun {
@@ -79,6 +80,8 @@ namespace Engine {
7980
ExecutionStrategyHandle& currentExecutor_;
8081

8182
boost::thread executionLaunchThread_;
83+
Core::Thread::Mutex executionMutex_;
84+
Core::Thread::ConditionVariable somethingToExecute_;
8285

8386
void executeTopContext();
8487
};

0 commit comments

Comments
 (0)