@@ -106,10 +106,17 @@ void ContainerBasePrivate::compute() {
106106 static_cast <ContainerBase*>(me_)->compute ();
107107}
108108
109+ template <Interface::Direction dir>
109110void ContainerBasePrivate::copyState (Interface::iterator external, const InterfacePtr& target, bool updated) {
110- // TODO: update internal's prio from external's new priority
111- if (updated)
111+ if (updated) {
112+ // TODO(v4hn): This is inefficient, consider storing inverse mapping for each start/end pair in children
113+ // for parallel containers there will be multiple internal states
114+ std::for_each (internal_to_external_.begin (), internal_to_external_.end (), [&external](auto & p) {
115+ if (p.second == &*external)
116+ setStatus<dir>(p.first , external->priority ().status ());
117+ });
112118 return ;
119+ }
113120
114121 // create a clone of external state within target interface (child's starts() or ends())
115122 auto internal = states_.insert (states_.end (), InterfaceState (*external));
@@ -497,8 +504,9 @@ void SerialContainerPrivate::resolveInterface(InterfaceFlags expected) {
497504 validateInterface<START_IF_MASK>(*first.pimpl (), expected);
498505 // connect first child's (start) pull interface
499506 if (const InterfacePtr& target = first.pimpl ()->starts ())
500- starts_.reset (new Interface (
501- [this , target](Interface::iterator it, bool updated) { this ->copyState (it, target, updated); }));
507+ starts_.reset (new Interface ([this , target](Interface::iterator it, bool updated) {
508+ this ->copyState <Interface::FORWARD>(it, target, updated);
509+ }));
502510 } catch (InitStageException& e) {
503511 exceptions.append (e);
504512 }
@@ -521,8 +529,9 @@ void SerialContainerPrivate::resolveInterface(InterfaceFlags expected) {
521529 validateInterface<END_IF_MASK>(*last.pimpl (), expected);
522530 // connect last child's (end) pull interface
523531 if (const InterfacePtr& target = last.pimpl ()->ends ())
524- ends_.reset (new Interface (
525- [this , target](Interface::iterator it, bool updated) { this ->copyState (it, target, updated); }));
532+ ends_.reset (new Interface ([this , target](Interface::iterator it, bool updated) {
533+ this ->copyState <Interface::BACKWARD>(it, target, updated);
534+ }));
526535 } catch (InitStageException& e) {
527536 exceptions.append (e);
528537 }
@@ -622,11 +631,11 @@ void ParallelContainerBasePrivate::resolveInterface(InterfaceFlags expected) {
622631 // States received by the container need to be copied to all children's pull interfaces.
623632 if (expected & READS_START)
624633 starts ().reset (new Interface ([this ](Interface::iterator external, bool updated) {
625- this ->onNewExternalState ( Interface::FORWARD, external, updated);
634+ this ->onNewExternalState < Interface::FORWARD>( external, updated);
626635 }));
627636 if (expected & READS_END)
628637 ends ().reset (new Interface ([this ](Interface::iterator external, bool updated) {
629- this ->onNewExternalState ( Interface::BACKWARD, external, updated);
638+ this ->onNewExternalState < Interface::BACKWARD>( external, updated);
630639 }));
631640
632641 required_interface_ = expected;
@@ -663,10 +672,10 @@ void ParallelContainerBasePrivate::validateConnectivity() const {
663672 ContainerBasePrivate::validateConnectivity ();
664673}
665674
666- void ParallelContainerBasePrivate::onNewExternalState ( Interface::Direction dir, Interface::iterator external,
667- bool updated) {
675+ template < Interface::Direction dir>
676+ void ParallelContainerBasePrivate::onNewExternalState (Interface::iterator external, bool updated) {
668677 for (const Stage::pointer& stage : children ())
669- copyState (external, stage->pimpl ()->pullInterface (dir), updated);
678+ copyState<dir> (external, stage->pimpl ()->pullInterface (dir), updated);
670679}
671680
672681ParallelContainerBase::ParallelContainerBase (ParallelContainerBasePrivate* impl) : ContainerBase(impl) {}
0 commit comments