diff --git a/dataflow_cpp/include/embb/dataflow/internal/constant_source.h b/dataflow_cpp/include/embb/dataflow/internal/constant_source.h index 6b11039..6cf2260 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/constant_source.h +++ b/dataflow_cpp/include/embb/dataflow/internal/constant_source.h @@ -46,9 +46,9 @@ class ConstantSource Type value_; public: - explicit ConstantSource(Network & network, Type value) + ConstantSource(Scheduler * sched, Type value) : value_(value) { - SetScheduler(network.GetScheduler()); + SetScheduler(sched); } virtual bool HasOutputs() const { diff --git a/dataflow_cpp/include/embb/dataflow/internal/inputs.h b/dataflow_cpp/include/embb/dataflow/internal/inputs.h index aef0df4..81282dd 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/inputs.h +++ b/dataflow_cpp/include/embb/dataflow/internal/inputs.h @@ -168,7 +168,7 @@ class Inputstemplate Get<0>().IsConnected() & this->template Get<1>().IsConnected(); } -private: + private: embb::base::Atomic * count_; ClockListener * listener_; int slices_; @@ -233,7 +233,7 @@ class Inputstemplate Get<1>().IsConnected() & this->template Get<2>().IsConnected(); } -private: + private: embb::base::Atomic * count_; ClockListener * listener_; int slices_; diff --git a/dataflow_cpp/include/embb/dataflow/internal/process.h b/dataflow_cpp/include/embb/dataflow/internal/process.h index 9d05881..1dfade2 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/process.h +++ b/dataflow_cpp/include/embb/dataflow/internal/process.h @@ -53,11 +53,11 @@ class Process< Serial, Inputs, typedef ProcessExecutor< InputsType, OutputsType > ExecutorType; typedef typename ExecutorType::FunctionType FunctionType; - explicit Process(Network & network, FunctionType function) - : inputs_(network.GetSlices()) + Process(int slices, Scheduler * sched, FunctionType function) + : inputs_(slices) , executor_(function) , action_(NULL) - , slices_(network.GetSlices()) { + , slices_(slices) { next_clock_ = 0; queued_clock_ = 0; bool ordered = Serial; @@ -73,7 +73,7 @@ class Process< Serial, Inputs, for (int ii = 0; ii < slices_; ii++) { action_[ii] = Action(); } - SetScheduler(network.GetScheduler()); + SetScheduler(sched); } ~Process() { diff --git a/dataflow_cpp/include/embb/dataflow/internal/scheduler_mtapi.h b/dataflow_cpp/include/embb/dataflow/internal/scheduler_mtapi.h index 14b559f..856b4a2 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/scheduler_mtapi.h +++ b/dataflow_cpp/include/embb/dataflow/internal/scheduler_mtapi.h @@ -40,7 +40,7 @@ namespace internal { class SchedulerMTAPI : public Scheduler { public: - SchedulerMTAPI(int slices) + explicit SchedulerMTAPI(int slices) : slices_(slices) { embb::tasks::Node & node = embb::tasks::Node::GetInstance(); diff --git a/dataflow_cpp/include/embb/dataflow/internal/select.h b/dataflow_cpp/include/embb/dataflow/internal/select.h index 8cc28a0..c90758f 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/select.h +++ b/dataflow_cpp/include/embb/dataflow/internal/select.h @@ -34,9 +34,6 @@ namespace embb { namespace dataflow { - -class Network; - namespace internal { template @@ -47,10 +44,9 @@ class Select typedef Inputs InputsType; typedef Outputs OutputsType; - Select(Network & network) : inputs_(network.GetSlices()) { + Select(int slices, Scheduler * sched) : inputs_(slices), slices_(slices) { inputs_.SetListener(this); - slices_ = network.GetSlices(); - SetScheduler(network.GetScheduler()); + SetScheduler(sched); } virtual bool HasInputs() const { diff --git a/dataflow_cpp/include/embb/dataflow/internal/sink.h b/dataflow_cpp/include/embb/dataflow/internal/sink.h index 6ff367e..1f59464 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/sink.h +++ b/dataflow_cpp/include/embb/dataflow/internal/sink.h @@ -48,11 +48,12 @@ class Sink< Inputs > typedef SinkExecutor< InputsType > ExecutorType; typedef typename ExecutorType::FunctionType FunctionType; - explicit Sink(Network & network, FunctionType function) - : inputs_(network.GetSlices()) + Sink(int slices, Scheduler * sched, ClockListener * listener, + FunctionType function) + : inputs_(slices) , executor_(function) , action_(NULL) - , slices_(network.GetSlices()) { + , slices_(slices) { next_clock_ = 0; queued_clock_ = 0; queue_id_ = GetNextProcessID(); @@ -63,8 +64,8 @@ class Sink< Inputs > for (int ii = 0; ii < slices_; ii++) { action_[ii] = Action(); } - SetListener(&network); - SetScheduler(network.GetScheduler()); + SetListener(listener); + SetScheduler(sched); } ~Sink() { diff --git a/dataflow_cpp/include/embb/dataflow/internal/source.h b/dataflow_cpp/include/embb/dataflow/internal/source.h index 067a85e..26d3734 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/source.h +++ b/dataflow_cpp/include/embb/dataflow/internal/source.h @@ -48,9 +48,9 @@ class Source< Outputs > typedef SourceExecutor< OutputsType > ExecutorType; typedef typename ExecutorType::FunctionType FunctionType; - explicit Source(Network & network, FunctionType function) + Source(Scheduler * sched, FunctionType function) : executor_(function), not_done_(true) { - SetScheduler(network.GetScheduler()); + SetScheduler(sched); } virtual bool HasOutputs() const { diff --git a/dataflow_cpp/include/embb/dataflow/internal/switch.h b/dataflow_cpp/include/embb/dataflow/internal/switch.h index 55d4110..db02058 100644 --- a/dataflow_cpp/include/embb/dataflow/internal/switch.h +++ b/dataflow_cpp/include/embb/dataflow/internal/switch.h @@ -34,9 +34,6 @@ namespace embb { namespace dataflow { - -class Network; - namespace internal { template @@ -47,9 +44,9 @@ class Switch typedef Inputs InputsType; typedef Outputs OutputsType; - Switch(Network & network) : inputs_(network.GetSlices()) { + Switch(int slices, Scheduler * sched) : inputs_(slices) { inputs_.SetListener(this); - SetScheduler(network.GetScheduler()); + SetScheduler(sched); } virtual bool HasInputs() const { diff --git a/dataflow_cpp/include/embb/dataflow/network.h b/dataflow_cpp/include/embb/dataflow/network.h index 0719e3b..9b54d7e 100644 --- a/dataflow_cpp/include/embb/dataflow/network.h +++ b/dataflow_cpp/include/embb/dataflow/network.h @@ -60,7 +60,7 @@ class Network { * Constructs an empty network. * \param slices Number of concurrent tokens allowed in the network. */ - Network(int slices) {} + explicit Network(int slices) {} /** * Input port class. @@ -681,7 +681,8 @@ class Network { class Network : public internal::ClockListener { public: - Network(int slices) : sink_counter_(NULL), slices_(slices), sched_(NULL) { + explicit Network(int slices) + : sink_counter_(NULL), slices_(slices), sched_(NULL) { sched_ = embb::base::Allocation::New(slices_); sink_counter_ = reinterpret_cast*>( embb::base::Allocation::Allocate( @@ -709,7 +710,8 @@ class Network : public internal::ClockListener { typename T5 = embb::base::internal::Nil> class Inputs : public internal::Inputs { public: - explicit Inputs(int slices) : internal::Inputs(slices) {} + explicit Inputs(int slices) + : internal::Inputs(slices) {} }; template class Outputs : public internal::Outputs { public: - explicit Outputs() : internal::Outputs() {} + explicit Outputs() + : internal::Outputs() {} }; template class SerialProcess; @@ -739,7 +742,8 @@ class Network : public internal::ClockListener { explicit SerialProcess(Network & network, FunctionType function) : internal::Process< true, internal::Inputs, - internal::Outputs >(network, function) { + internal::Outputs >( + network.slices_, network.sched_, function) { network.processes_.push_back(this); } }; @@ -762,7 +766,8 @@ class Network : public internal::ClockListener { explicit ParallelProcess(Network & network, FunctionType function) : internal::Process< false, internal::Inputs, - internal::Outputs >(network, function) { + internal::Outputs >( + network.slices_, network.sched_, function) { network.processes_.push_back(this); } }; @@ -771,7 +776,7 @@ class Network : public internal::ClockListener { class Switch : public internal::Switch { public: explicit Switch(Network & network) - : internal::Switch(network) { + : internal::Switch(network.slices_, network.sched_) { network.processes_.push_back(this); } }; @@ -780,7 +785,7 @@ class Network : public internal::ClockListener { class Select : public internal::Select { public: explicit Select(Network & network) - : internal::Select(network) { + : internal::Select(network.slices_, network.sched_) { network.processes_.push_back(this); } }; @@ -797,7 +802,8 @@ class Network : public internal::ClockListener { explicit Sink(Network & network, FunctionType function) : internal::Sink< - internal::Inputs >(network, function) { + internal::Inputs >( + network.slices_, network.sched_, &network, function) { network.sinks_.push_back(this); network.sink_count_++; } @@ -816,7 +822,7 @@ class Network : public internal::ClockListener { explicit Source(Network & network, FunctionType function) : internal::Source< - internal::Outputs >(network, function) { + internal::Outputs >(network.sched_, function) { network.sources_.push_back(this); } }; @@ -825,19 +831,11 @@ class Network : public internal::ClockListener { class ConstantSource : public internal::ConstantSource { public: explicit ConstantSource(Network & network, Type value) - : internal::ConstantSource(network, value) { + : internal::ConstantSource(network.sched_, value) { network.sources_.push_back(this); } }; - int GetSlices() const { - return slices_; - } - - internal::Scheduler * GetScheduler() const { - return sched_; - } - bool IsValid() { bool valid = true; for (size_t ii = 0; ii < sources_.size(); ii++) { diff --git a/dataflow_cpp/test/dataflow_cpp_test_simple.cc b/dataflow_cpp/test/dataflow_cpp_test_simple.cc index da96399..c73a0f1 100644 --- a/dataflow_cpp/test/dataflow_cpp_test_simple.cc +++ b/dataflow_cpp/test/dataflow_cpp_test_simple.cc @@ -170,7 +170,8 @@ void SimpleTest::TestBasic() { MySource source(network, embb::base::MakeFunction(sourceFunc)); MyFilter filter(network, embb::base::MakeFunction(filterFunc)); MyMult mult(network, embb::base::MakeFunction(multFunc)); - MySink sink(network, embb::base::MakeFunction(asink, &ArraySink::Run)); + MySink sink(network, + embb::base::MakeFunction(asink, &ArraySink::Run)); MyPred pred(network, embb::base::MakeFunction(predFunc)); MySwitch sw(network); MySelect sel(network); @@ -208,11 +209,6 @@ void SimpleTest::TestBasic() { sel.GetOutput<0>() >> sink.GetInput<0>(); -// network.AddSource(constant); -// network.AddSource(source); - -// network.Initialize(NUM_SLICES); - try { if (!network.IsValid()) { EMBB_THROW(embb::base::ErrorException, "network is invalid"); diff --git a/tasks_cpp/src/node.cc b/tasks_cpp/src/node.cc index 409510f..8dc49b0 100644 --- a/tasks_cpp/src/node.cc +++ b/tasks_cpp/src/node.cc @@ -41,7 +41,7 @@ namespace { static embb::tasks::Node * node_instance = NULL; #if TASKS_CPP_AUTOMATIC_INITIALIZE -static embb_spinlock_t init_mutex = { 0 }; +static embb_spinlock_t init_mutex = { { 0 } }; #endif }