Commit 582bb5a1 by Marcus Winter

dataflow_cpp: linux fixes

parent c3872ad0
...@@ -46,9 +46,9 @@ class ConstantSource ...@@ -46,9 +46,9 @@ class ConstantSource
Type value_; Type value_;
public: public:
explicit ConstantSource(Network & network, Type value) ConstantSource(Scheduler * sched, Type value)
: value_(value) { : value_(value) {
SetScheduler(network.GetScheduler()); SetScheduler(sched);
} }
virtual bool HasOutputs() const { virtual bool HasOutputs() const {
......
...@@ -168,7 +168,7 @@ class Inputs<T1, T2, embb::base::internal::Nil, ...@@ -168,7 +168,7 @@ class Inputs<T1, T2, embb::base::internal::Nil,
return this->template Get<0>().IsConnected() & return this->template Get<0>().IsConnected() &
this->template Get<1>().IsConnected(); this->template Get<1>().IsConnected();
} }
private: private:
embb::base::Atomic<int> * count_; embb::base::Atomic<int> * count_;
ClockListener * listener_; ClockListener * listener_;
int slices_; int slices_;
...@@ -233,7 +233,7 @@ class Inputs<T1, T2, T3, embb::base::internal::Nil, ...@@ -233,7 +233,7 @@ class Inputs<T1, T2, T3, embb::base::internal::Nil,
this->template Get<1>().IsConnected() & this->template Get<1>().IsConnected() &
this->template Get<2>().IsConnected(); this->template Get<2>().IsConnected();
} }
private: private:
embb::base::Atomic<int> * count_; embb::base::Atomic<int> * count_;
ClockListener * listener_; ClockListener * listener_;
int slices_; int slices_;
......
...@@ -53,11 +53,11 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>, ...@@ -53,11 +53,11 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>,
typedef ProcessExecutor< InputsType, OutputsType > ExecutorType; typedef ProcessExecutor< InputsType, OutputsType > ExecutorType;
typedef typename ExecutorType::FunctionType FunctionType; typedef typename ExecutorType::FunctionType FunctionType;
explicit Process(Network & network, FunctionType function) Process(int slices, Scheduler * sched, FunctionType function)
: inputs_(network.GetSlices()) : inputs_(slices)
, executor_(function) , executor_(function)
, action_(NULL) , action_(NULL)
, slices_(network.GetSlices()) { , slices_(slices) {
next_clock_ = 0; next_clock_ = 0;
queued_clock_ = 0; queued_clock_ = 0;
bool ordered = Serial; bool ordered = Serial;
...@@ -73,7 +73,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>, ...@@ -73,7 +73,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>,
for (int ii = 0; ii < slices_; ii++) { for (int ii = 0; ii < slices_; ii++) {
action_[ii] = Action(); action_[ii] = Action();
} }
SetScheduler(network.GetScheduler()); SetScheduler(sched);
} }
~Process() { ~Process() {
......
...@@ -40,7 +40,7 @@ namespace internal { ...@@ -40,7 +40,7 @@ namespace internal {
class SchedulerMTAPI : public Scheduler { class SchedulerMTAPI : public Scheduler {
public: public:
SchedulerMTAPI(int slices) explicit SchedulerMTAPI(int slices)
: slices_(slices) { : slices_(slices) {
embb::tasks::Node & node = embb::tasks::Node::GetInstance(); embb::tasks::Node & node = embb::tasks::Node::GetInstance();
......
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
namespace embb { namespace embb {
namespace dataflow { namespace dataflow {
class Network;
namespace internal { namespace internal {
template <typename Type> template <typename Type>
...@@ -47,10 +44,9 @@ class Select ...@@ -47,10 +44,9 @@ class Select
typedef Inputs<bool, Type, Type> InputsType; typedef Inputs<bool, Type, Type> InputsType;
typedef Outputs<Type> OutputsType; typedef Outputs<Type> OutputsType;
Select(Network & network) : inputs_(network.GetSlices()) { Select(int slices, Scheduler * sched) : inputs_(slices), slices_(slices) {
inputs_.SetListener(this); inputs_.SetListener(this);
slices_ = network.GetSlices(); SetScheduler(sched);
SetScheduler(network.GetScheduler());
} }
virtual bool HasInputs() const { virtual bool HasInputs() const {
......
...@@ -48,11 +48,12 @@ class Sink< Inputs<I1, I2, I3, I4, I5> > ...@@ -48,11 +48,12 @@ class Sink< Inputs<I1, I2, I3, I4, I5> >
typedef SinkExecutor< InputsType > ExecutorType; typedef SinkExecutor< InputsType > ExecutorType;
typedef typename ExecutorType::FunctionType FunctionType; typedef typename ExecutorType::FunctionType FunctionType;
explicit Sink(Network & network, FunctionType function) Sink(int slices, Scheduler * sched, ClockListener * listener,
: inputs_(network.GetSlices()) FunctionType function)
: inputs_(slices)
, executor_(function) , executor_(function)
, action_(NULL) , action_(NULL)
, slices_(network.GetSlices()) { , slices_(slices) {
next_clock_ = 0; next_clock_ = 0;
queued_clock_ = 0; queued_clock_ = 0;
queue_id_ = GetNextProcessID(); queue_id_ = GetNextProcessID();
...@@ -63,8 +64,8 @@ class Sink< Inputs<I1, I2, I3, I4, I5> > ...@@ -63,8 +64,8 @@ class Sink< Inputs<I1, I2, I3, I4, I5> >
for (int ii = 0; ii < slices_; ii++) { for (int ii = 0; ii < slices_; ii++) {
action_[ii] = Action(); action_[ii] = Action();
} }
SetListener(&network); SetListener(listener);
SetScheduler(network.GetScheduler()); SetScheduler(sched);
} }
~Sink() { ~Sink() {
......
...@@ -48,9 +48,9 @@ class Source< Outputs<O1, O2, O3, O4, O5> > ...@@ -48,9 +48,9 @@ class Source< Outputs<O1, O2, O3, O4, O5> >
typedef SourceExecutor< OutputsType > ExecutorType; typedef SourceExecutor< OutputsType > ExecutorType;
typedef typename ExecutorType::FunctionType FunctionType; typedef typename ExecutorType::FunctionType FunctionType;
explicit Source(Network & network, FunctionType function) Source(Scheduler * sched, FunctionType function)
: executor_(function), not_done_(true) { : executor_(function), not_done_(true) {
SetScheduler(network.GetScheduler()); SetScheduler(sched);
} }
virtual bool HasOutputs() const { virtual bool HasOutputs() const {
......
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
namespace embb { namespace embb {
namespace dataflow { namespace dataflow {
class Network;
namespace internal { namespace internal {
template <typename Type> template <typename Type>
...@@ -47,9 +44,9 @@ class Switch ...@@ -47,9 +44,9 @@ class Switch
typedef Inputs<bool, Type> InputsType; typedef Inputs<bool, Type> InputsType;
typedef Outputs<Type, Type> OutputsType; typedef Outputs<Type, Type> OutputsType;
Switch(Network & network) : inputs_(network.GetSlices()) { Switch(int slices, Scheduler * sched) : inputs_(slices) {
inputs_.SetListener(this); inputs_.SetListener(this);
SetScheduler(network.GetScheduler()); SetScheduler(sched);
} }
virtual bool HasInputs() const { virtual bool HasInputs() const {
......
...@@ -60,7 +60,7 @@ class Network { ...@@ -60,7 +60,7 @@ class Network {
* Constructs an empty network. * Constructs an empty network.
* \param slices Number of concurrent tokens allowed in the network. * \param slices Number of concurrent tokens allowed in the network.
*/ */
Network(int slices) {} explicit Network(int slices) {}
/** /**
* Input port class. * Input port class.
...@@ -681,7 +681,8 @@ class Network { ...@@ -681,7 +681,8 @@ class Network {
class Network : public internal::ClockListener { class Network : public internal::ClockListener {
public: 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<internal::SchedulerMTAPI>(slices_); sched_ = embb::base::Allocation::New<internal::SchedulerMTAPI>(slices_);
sink_counter_ = reinterpret_cast<embb::base::Atomic<int>*>( sink_counter_ = reinterpret_cast<embb::base::Atomic<int>*>(
embb::base::Allocation::Allocate( embb::base::Allocation::Allocate(
...@@ -709,7 +710,8 @@ class Network : public internal::ClockListener { ...@@ -709,7 +710,8 @@ class Network : public internal::ClockListener {
typename T5 = embb::base::internal::Nil> typename T5 = embb::base::internal::Nil>
class Inputs : public internal::Inputs<T1, T2, T3, T4, T5> { class Inputs : public internal::Inputs<T1, T2, T3, T4, T5> {
public: public:
explicit Inputs(int slices) : internal::Inputs(slices) {} explicit Inputs(int slices)
: internal::Inputs<T1, T2, T3, T4, T5>(slices) {}
}; };
template <typename T1, typename T2 = embb::base::internal::Nil, template <typename T1, typename T2 = embb::base::internal::Nil,
...@@ -718,7 +720,8 @@ class Network : public internal::ClockListener { ...@@ -718,7 +720,8 @@ class Network : public internal::ClockListener {
typename T5 = embb::base::internal::Nil> typename T5 = embb::base::internal::Nil>
class Outputs : public internal::Outputs<T1, T2, T3, T4, T5> { class Outputs : public internal::Outputs<T1, T2, T3, T4, T5> {
public: public:
explicit Outputs() : internal::Outputs() {} explicit Outputs()
: internal::Outputs<T1, T2, T3, T4, T5>() {}
}; };
template <class Inputs, class Outputs> class SerialProcess; template <class Inputs, class Outputs> class SerialProcess;
...@@ -739,7 +742,8 @@ class Network : public internal::ClockListener { ...@@ -739,7 +742,8 @@ class Network : public internal::ClockListener {
explicit SerialProcess(Network & network, FunctionType function) explicit SerialProcess(Network & network, FunctionType function)
: internal::Process< true, : internal::Process< true,
internal::Inputs<I1, I2, I3, I4, I5>, internal::Inputs<I1, I2, I3, I4, I5>,
internal::Outputs<O1, O2, O3, O4, O5> >(network, function) { internal::Outputs<O1, O2, O3, O4, O5> >(
network.slices_, network.sched_, function) {
network.processes_.push_back(this); network.processes_.push_back(this);
} }
}; };
...@@ -762,7 +766,8 @@ class Network : public internal::ClockListener { ...@@ -762,7 +766,8 @@ class Network : public internal::ClockListener {
explicit ParallelProcess(Network & network, FunctionType function) explicit ParallelProcess(Network & network, FunctionType function)
: internal::Process< false, : internal::Process< false,
internal::Inputs<I1, I2, I3, I4, I5>, internal::Inputs<I1, I2, I3, I4, I5>,
internal::Outputs<O1, O2, O3, O4, O5> >(network, function) { internal::Outputs<O1, O2, O3, O4, O5> >(
network.slices_, network.sched_, function) {
network.processes_.push_back(this); network.processes_.push_back(this);
} }
}; };
...@@ -771,7 +776,7 @@ class Network : public internal::ClockListener { ...@@ -771,7 +776,7 @@ class Network : public internal::ClockListener {
class Switch : public internal::Switch<Type> { class Switch : public internal::Switch<Type> {
public: public:
explicit Switch(Network & network) explicit Switch(Network & network)
: internal::Switch<Type>(network) { : internal::Switch<Type>(network.slices_, network.sched_) {
network.processes_.push_back(this); network.processes_.push_back(this);
} }
}; };
...@@ -780,7 +785,7 @@ class Network : public internal::ClockListener { ...@@ -780,7 +785,7 @@ class Network : public internal::ClockListener {
class Select : public internal::Select<Type> { class Select : public internal::Select<Type> {
public: public:
explicit Select(Network & network) explicit Select(Network & network)
: internal::Select<Type>(network) { : internal::Select<Type>(network.slices_, network.sched_) {
network.processes_.push_back(this); network.processes_.push_back(this);
} }
}; };
...@@ -797,7 +802,8 @@ class Network : public internal::ClockListener { ...@@ -797,7 +802,8 @@ class Network : public internal::ClockListener {
explicit Sink(Network & network, FunctionType function) explicit Sink(Network & network, FunctionType function)
: internal::Sink< : internal::Sink<
internal::Inputs<I1, I2, I3, I4, I5> >(network, function) { internal::Inputs<I1, I2, I3, I4, I5> >(
network.slices_, network.sched_, &network, function) {
network.sinks_.push_back(this); network.sinks_.push_back(this);
network.sink_count_++; network.sink_count_++;
} }
...@@ -816,7 +822,7 @@ class Network : public internal::ClockListener { ...@@ -816,7 +822,7 @@ class Network : public internal::ClockListener {
explicit Source(Network & network, FunctionType function) explicit Source(Network & network, FunctionType function)
: internal::Source< : internal::Source<
internal::Outputs<O1, O2, O3, O4, O5> >(network, function) { internal::Outputs<O1, O2, O3, O4, O5> >(network.sched_, function) {
network.sources_.push_back(this); network.sources_.push_back(this);
} }
}; };
...@@ -825,19 +831,11 @@ class Network : public internal::ClockListener { ...@@ -825,19 +831,11 @@ class Network : public internal::ClockListener {
class ConstantSource : public internal::ConstantSource<Type> { class ConstantSource : public internal::ConstantSource<Type> {
public: public:
explicit ConstantSource(Network & network, Type value) explicit ConstantSource(Network & network, Type value)
: internal::ConstantSource<Type>(network, value) { : internal::ConstantSource<Type>(network.sched_, value) {
network.sources_.push_back(this); network.sources_.push_back(this);
} }
}; };
int GetSlices() const {
return slices_;
}
internal::Scheduler * GetScheduler() const {
return sched_;
}
bool IsValid() { bool IsValid() {
bool valid = true; bool valid = true;
for (size_t ii = 0; ii < sources_.size(); ii++) { for (size_t ii = 0; ii < sources_.size(); ii++) {
......
...@@ -170,7 +170,8 @@ void SimpleTest::TestBasic() { ...@@ -170,7 +170,8 @@ void SimpleTest::TestBasic() {
MySource source(network, embb::base::MakeFunction(sourceFunc)); MySource source(network, embb::base::MakeFunction(sourceFunc));
MyFilter filter(network, embb::base::MakeFunction(filterFunc)); MyFilter filter(network, embb::base::MakeFunction(filterFunc));
MyMult mult(network, embb::base::MakeFunction(multFunc)); MyMult mult(network, embb::base::MakeFunction(multFunc));
MySink sink(network, embb::base::MakeFunction(asink, &ArraySink<TEST_COUNT>::Run)); MySink sink(network,
embb::base::MakeFunction(asink, &ArraySink<TEST_COUNT>::Run));
MyPred pred(network, embb::base::MakeFunction(predFunc)); MyPred pred(network, embb::base::MakeFunction(predFunc));
MySwitch sw(network); MySwitch sw(network);
MySelect sel(network); MySelect sel(network);
...@@ -208,11 +209,6 @@ void SimpleTest::TestBasic() { ...@@ -208,11 +209,6 @@ void SimpleTest::TestBasic() {
sel.GetOutput<0>() >> sink.GetInput<0>(); sel.GetOutput<0>() >> sink.GetInput<0>();
// network.AddSource(constant);
// network.AddSource(source);
// network.Initialize(NUM_SLICES);
try { try {
if (!network.IsValid()) { if (!network.IsValid()) {
EMBB_THROW(embb::base::ErrorException, "network is invalid"); EMBB_THROW(embb::base::ErrorException, "network is invalid");
......
...@@ -41,7 +41,7 @@ namespace { ...@@ -41,7 +41,7 @@ namespace {
static embb::tasks::Node * node_instance = NULL; static embb::tasks::Node * node_instance = NULL;
#if TASKS_CPP_AUTOMATIC_INITIALIZE #if TASKS_CPP_AUTOMATIC_INITIALIZE
static embb_spinlock_t init_mutex = { 0 }; static embb_spinlock_t init_mutex = { { 0 } };
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment