Skip to content

Commit

Permalink
iox-eclipse-iceoryx#221 port_manager: exchange iterator copies with e…
Browse files Browse the repository at this point in the history
…lement references, limit lambda variable capturing to needed scope

Signed-off-by: Eickhoff Bernhard (CC-AD/ESW1) <[email protected]>
  • Loading branch information
bishibashiB committed Aug 24, 2020
1 parent b7f9475 commit a2b8a79
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
66 changes: 33 additions & 33 deletions iceoryx_posh/source/roudi/port_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ void PortManager::handleSenderPorts()
auto& senderList = m_portPool->senderPortDataList();
for (auto iter = senderList.begin(); iter != senderList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
SenderPortType senderPort(checkIter.operator->());
SenderPortType senderPort(&portData);
auto returnedCaproMessage = senderPort.getCaProMessage();
if (returnedCaproMessage.has_value())
{
Expand Down Expand Up @@ -138,7 +138,7 @@ void PortManager::handleSenderPorts()
// check if we have to destroy this sender port
if (senderPort.toBeDestroyed())
{
destroySenderPort(*checkIter);
destroySenderPort(portData);
}
}
}
Expand All @@ -149,9 +149,9 @@ void PortManager::handleReceiverPorts()
auto& receiverList = m_portPool->receiverPortDataList();
for (auto iter = receiverList.begin(); iter != receiverList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
ReceiverPortType receiverPort(checkIter.operator->());
ReceiverPortType receiverPort(&portData);
auto returnedCaproMessage = receiverPort.getCaProMessage();
if (returnedCaproMessage.has_value())
{
Expand All @@ -170,7 +170,7 @@ void PortManager::handleReceiverPorts()
// check if we have to destroy this sender port
if (receiverPort.toBeDestroyed())
{
destroyReceiverPort(*checkIter);
destroyReceiverPort(portData);
}
}
}
Expand All @@ -183,18 +183,18 @@ void PortManager::handleInterfaces()
auto& interfaceList = m_portPool->interfacePortDataList();
for (auto iter = interfaceList.begin(); iter != interfaceList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
if (checkIter->m_doInitialOfferForward)
if (portData.m_doInitialOfferForward)
{
interfacePortsForInitialForwarding.push_back(checkIter.operator->());
checkIter->m_doInitialOfferForward = false;
interfacePortsForInitialForwarding.push_back(&portData);
portData.m_doInitialOfferForward = false;
}

// check if we have to destroy this interface port
if (checkIter->m_toBeDestroyed)
if (portData.m_toBeDestroyed)
{
m_portPool->removeInterfacePort(checkIter.operator->());
m_portPool->removeInterfacePort(&portData);
LogDebug() << "Destroyed InterfacePortData";
}
}
Expand Down Expand Up @@ -258,9 +258,9 @@ void PortManager::handleApplications()
auto& appList = m_portPool->appliactionPortDataList();
for (auto iter = appList.begin(); iter != appList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
iox::popo::ApplicationPort applicationPort(checkIter.operator->());
iox::popo::ApplicationPort applicationPort(&portData);

while (auto maybeCaproMessage = applicationPort.getCaProMessage())
{
Expand Down Expand Up @@ -295,7 +295,7 @@ void PortManager::handleApplications()
// check if we have to destroy this application port
if (applicationPort.toBeDestroyed())
{
m_portPool->removeApplicationPort(checkIter.operator->());
m_portPool->removeApplicationPort(&portData);
LogDebug() << "Destroyed ApplicationPortData";
}
}
Expand All @@ -311,12 +311,12 @@ void PortManager::handleRunnables()
auto& runnableList = m_portPool->runnableDataList();
for (auto iter = runnableList.begin(); iter != runnableList.cend();)
{
auto checkIter = iter;
auto& RunnableData = *iter;
++iter;

if (checkIter->m_toBeDestroyed)
if (RunnableData.m_toBeDestroyed)
{
m_portPool->removeRunnableData(checkIter.operator->());
m_portPool->removeRunnableData(&RunnableData);
LogDebug() << "Destroyed RunnableData";
}
}
Expand Down Expand Up @@ -419,61 +419,61 @@ void PortManager::deletePortsOfProcess(std::string processName)
auto& senderList = m_portPool->senderPortDataList();
for (auto iter = senderList.begin(); iter != senderList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
SenderPortType sender(checkIter.operator->());
SenderPortType sender(&portData);
if (processName == sender.getProcessName())
{
destroySenderPort(*checkIter);
destroySenderPort(portData);
}
}

auto& receiverList = m_portPool->receiverPortDataList();
for (auto iter = receiverList.begin(); iter != receiverList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
ReceiverPortType receiver(checkIter.operator->());
ReceiverPortType receiver(&portData);
if (processName == receiver.getProcessName())
{
destroyReceiverPort(*checkIter);
destroyReceiverPort(portData);
}
}

auto& interfaceList = m_portPool->interfacePortDataList();
for (auto iter = interfaceList.begin(); iter != interfaceList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
popo::InterfacePort interface(checkIter.operator->());
popo::InterfacePort interface(&portData);
if (processName == interface.getProcessName())
{
m_portPool->removeInterfacePort(checkIter.operator->());
m_portPool->removeInterfacePort(&portData);
LogDebug() << "Deleted Interface of application " << processName;
}
}

auto& appList = m_portPool->appliactionPortDataList();
for (auto iter = appList.begin(); iter != appList.cend();)
{
auto checkIter = iter;
auto& portData = *iter;
++iter;
popo::ApplicationPort application(checkIter.operator->());
popo::ApplicationPort application(&portData);
if (processName == application.getProcessName())
{
m_portPool->removeApplicationPort(checkIter.operator->());
m_portPool->removeApplicationPort(&portData);
LogDebug() << "Deleted ApplicationPort of application " << processName;
}
}

auto& runnableList = m_portPool->runnableDataList();
for (auto iter = runnableList.begin(); iter != runnableList.cend();)
{
auto checkIter = iter;
auto& RunnableData = *iter;
++iter;
if (processName == checkIter->m_process)
if (processName == RunnableData.m_process)
{
m_portPool->removeRunnableData(checkIter.operator->());
m_portPool->removeRunnableData(&RunnableData);
LogDebug() << "Deleted runnable of application " << processName;
}
}
Expand Down
7 changes: 4 additions & 3 deletions iceoryx_posh/source/roudi/port_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@ PortPool::addRunnableData(const iox::cxx::CString100& process,
void PortPool::removeInterfacePort(popo::InterfacePortData* const portData) noexcept
{
m_portPoolDataBase->m_interfacePortMembers.remove_if(
[&](popo::InterfacePortData& port) { return &port == portData; });
[portData](popo::InterfacePortData& port) { return &port == portData; });
}

void PortPool::removeApplicationPort(popo::ApplicationPortData* const portData) noexcept
{
m_portPoolDataBase->m_applicationPortMembers.remove_if(
[&](popo::ApplicationPortData& port) { return &port == portData; });
[portData](popo::ApplicationPortData& port) { return &port == portData; });
}

void PortPool::removeRunnableData(runtime::RunnableData* const runnableData) noexcept
{
m_portPoolDataBase->m_runnableMembers.remove_if([&](runtime::RunnableData& r) { return &r == runnableData; });
m_portPoolDataBase->m_runnableMembers.remove_if(
[runnableData](runtime::RunnableData& r) { return &r == runnableData; });
}

std::atomic<uint64_t>* PortPool::serviceRegistryChangeCounter() noexcept
Expand Down

0 comments on commit a2b8a79

Please sign in to comment.