Skip to content

Commit 4e12aaf

Browse files
committed
Push execution launching to separate thread
1 parent 2ef7b82 commit 4e12aaf

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/Dataflow/Engine/Controller/NetworkEditorController.cc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ NetworkEditorController::NetworkEditorController(ModuleFactoryHandle mf, ModuleS
6464
reexFactory_(reex),
6565
executorFactory_(executorFactory),
6666
serializationManager_(nesm),
67+
executionManager_(currentExecutor_), //TODO: pass in factory instead
6768
signalSwitch_(true)
6869
{
6970
dynamicPortManager_.reset(new DynamicPortManager(connectionAdded_, connectionRemoved_, this));
@@ -76,7 +77,7 @@ NetworkEditorController::NetworkEditorController(ModuleFactoryHandle mf, ModuleS
7677
}
7778

7879
NetworkEditorController::NetworkEditorController(SCIRun::Dataflow::Networks::NetworkHandle network, ExecutionStrategyFactoryHandle executorFactory, NetworkEditorSerializationManager* nesm)
79-
: theNetwork_(network), executorFactory_(executorFactory), serializationManager_(nesm)
80+
: theNetwork_(network), executorFactory_(executorFactory), serializationManager_(nesm), executionManager_(currentExecutor_) //TODO: pass in factory instead
8081
{
8182
}
8283

@@ -367,7 +368,31 @@ void NetworkEditorController::executeGeneric(const ExecutableLookup* lookup, Mod
367368
{
368369
initExecutor();
369370
auto context = createExecutionContext(lookup, filter);
370-
currentExecutor_->execute(*context);
371+
372+
executionManager_.enqueueContext(context);
373+
}
374+
375+
ExecutionQueueManager::ExecutionQueueManager(ExecutionStrategyHandle& currentExecutor) : contexts_(1), currentExecutor_(currentExecutor),
376+
executionLaunchThread_([this]() {executeTopContext(); } )
377+
{
378+
}
379+
380+
void ExecutionQueueManager::enqueueContext(ExecutionContextHandle context)
381+
{
382+
if (contexts_.push(context))
383+
std::cout << "ctx queued" << std::endl;
384+
else
385+
std::cout << "ctx queue is full" << std::endl;
386+
}
387+
388+
void ExecutionQueueManager::executeTopContext()
389+
{
390+
while (true)
391+
{
392+
if (contexts_.read_available())
393+
contexts_.consume_one([&](ExecutionContextHandle ctx) { currentExecutor_->execute(*ctx); });
394+
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
395+
}
371396
}
372397

373398
NetworkHandle NetworkEditorController::getNetwork() const

src/Dataflow/Engine/Controller/NetworkEditorController.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ namespace Engine {
8383
class SCISHARE NetworkEditorController : public NetworkIOInterface<Networks::NetworkFileHandle>, public Networks::NetworkEditorControllerInterface
8484
{
8585
public:
86-
explicit NetworkEditorController(Networks::ModuleFactoryHandle mf,
86+
NetworkEditorController(Networks::ModuleFactoryHandle mf,
8787
Networks::ModuleStateFactoryHandle sf,
8888
ExecutionStrategyFactoryHandle executorFactory,
8989
Core::Algorithms::AlgorithmFactoryHandle algoFactory,
9090
Networks::ReexecuteStrategyFactoryHandle reexFactory,
9191
Networks::NetworkEditorSerializationManager* nesm = 0);
92-
explicit NetworkEditorController(Networks::NetworkHandle network, ExecutionStrategyFactoryHandle executorFactory, Networks::NetworkEditorSerializationManager* nesm = 0);
92+
NetworkEditorController(Networks::NetworkHandle network, ExecutionStrategyFactoryHandle executorFactory, Networks::NetworkEditorSerializationManager* nesm = 0);
9393

9494
//////////////////////////////////////////////////////////////////////////
9595
//////////////////////Start: To be Pythonized/////////////////////////////
@@ -159,6 +159,8 @@ namespace Engine {
159159
ExecutionStrategyFactoryHandle executorFactory_;
160160
Networks::NetworkEditorSerializationManager* serializationManager_;
161161

162+
ExecutionQueueManager executionManager_;
163+
162164
ModuleAddedSignalType moduleAdded_;
163165
ModuleRemovedSignalType moduleRemoved_; //not used yet
164166
ConnectionAddedSignalType connectionAdded_;

src/Dataflow/Engine/Scheduler/ExecutionStrategy.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define ENGINE_SCHEDULER_EXECUTION_STRATEGY_H
3131

3232
#include <Dataflow/Engine/Scheduler/SchedulerInterfaces.h>
33+
#include <Dataflow/Engine/Scheduler/DynamicExecutor/WorkQueue.h>
34+
#include <boost/thread.hpp>
3335
#include <Dataflow/Engine/Scheduler/share.h>
3436

3537
namespace SCIRun {
@@ -64,6 +66,22 @@ namespace Engine {
6466

6567
typedef boost::shared_ptr<ExecutionStrategyFactory> ExecutionStrategyFactoryHandle;
6668

69+
70+
class SCISHARE ExecutionQueueManager
71+
{
72+
public:
73+
explicit ExecutionQueueManager(ExecutionStrategyHandle& currentExecutor);
74+
void enqueueContext(ExecutionContextHandle context);
75+
private:
76+
typedef DynamicExecutor::WorkQueue<ExecutionContextHandle>::Impl ExecutionContextQueue;
77+
ExecutionContextQueue contexts_;
78+
79+
ExecutionStrategyHandle& currentExecutor_;
80+
81+
boost::thread executionLaunchThread_;
82+
83+
void executeTopContext();
84+
};
6785
}
6886
}}
6987

0 commit comments

Comments
 (0)