Skip to content

Commit

Permalink
iox-#25: review findings
Browse files Browse the repository at this point in the history
Signed-off-by: Poehnl Michael (CC-AD/ESW1) <[email protected]>
  • Loading branch information
Poehnl Michael (CC-AD/ESW1) committed Apr 3, 2020
1 parent ea2725c commit 0f6e9e3
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ template <typename ChunkDistributorType>
inline cxx::expected<mepoo::ChunkHeader*, ChunkSenderError>
ChunkSender<ChunkDistributorType>::allocate(const uint32_t payloadSize) noexcept
{
// use the chunk stored in m_lastChunk if there is one, there is no other owner and the new payload fits in this
// chunk
// use the chunk stored in m_lastChunk if there is one, there is no other owner and the new payload still fits in it
uint32_t neededChunkSize = getMembers()->m_memoryMgr->sizeWithChunkHeaderStruct(payloadSize);

if (getMembers()->m_lastChunk && getMembers()->m_lastChunk.hasNoOtherOwners()
&& getMembers()->m_lastChunk.getChunkHeader()->m_info.m_usedSizeOfChunk
>= getMembers()->m_memoryMgr->sizeWithChunkHeaderStruct(payloadSize))
&& getMembers()->m_lastChunk.getChunkHeader()->m_info.m_totalSizeOfChunk >= neededChunkSize)
{
if (getMembers()->m_chunksInUse.insert(getMembers()->m_lastChunk))
{
getMembers()->m_lastChunk.getChunkHeader()->m_info.m_payloadSize = payloadSize;
getMembers()->m_lastChunk.getChunkHeader()->m_info.m_usedSizeOfChunk =
getMembers()->m_memoryMgr->sizeWithChunkHeaderStruct(payloadSize);
getMembers()->m_lastChunk.getChunkHeader()->m_info.m_usedSizeOfChunk = neededChunkSize;
return cxx::success<mepoo::ChunkHeader*>(getMembers()->m_lastChunk.getChunkHeader());
}
else
Expand All @@ -60,7 +59,7 @@ ChunkSender<ChunkDistributorType>::allocate(const uint32_t payloadSize) noexcept
}
else
{
// START of critical section, chunk will be lost if process gets hard terminated in between
// BEGIN of critical section, chunk will be lost if process gets hard terminated in between
// get a new chunk
mepoo::SharedChunk chunk = getMembers()->m_memoryMgr->getChunk(payloadSize);

Expand All @@ -69,7 +68,7 @@ ChunkSender<ChunkDistributorType>::allocate(const uint32_t payloadSize) noexcept
// if the application allocated too much chunks, return no more chunks
if (getMembers()->m_chunksInUse.insert(chunk))
{
// STOP of critical section, chunk will be lost if process gets hard terminated in between
// END of critical section, chunk will be lost if process gets hard terminated in between
return cxx::success<mepoo::ChunkHeader*>(chunk.getChunkHeader());
}
else
Expand Down Expand Up @@ -100,26 +99,26 @@ template <typename ChunkDistributorType>
inline void ChunkSender<ChunkDistributorType>::send(mepoo::ChunkHeader* const chunkHeader) noexcept
{
mepoo::SharedChunk chunk(nullptr);
// START of critical section, chunk will be lost if process gets hard terminated in between
// BEGIN of critical section, chunk will be lost if process gets hard terminated in between
if (getChunkReadyForSend(chunkHeader, chunk))
{
this->deliverToAllStoredQueues(chunk);
getMembers()->m_lastChunk = chunk;
}
// STOP of critical section, chunk will be lost if process gets hard terminated in between
// END of critical section, chunk will be lost if process gets hard terminated in between
}

template <typename ChunkDistributorType>
inline void ChunkSender<ChunkDistributorType>::pushToHistory(mepoo::ChunkHeader* const chunkHeader) noexcept
{
mepoo::SharedChunk chunk(nullptr);
// START of critical section, chunk will be lost if process gets hard terminated in between
// BEGIN of critical section, chunk will be lost if process gets hard terminated in between
if (getChunkReadyForSend(chunkHeader, chunk))
{
this->addToHistoryWithoutDelivery(chunk);
getMembers()->m_lastChunk = chunk;
}
// STOP of critical section, chunk will be lost if process gets hard terminated in between
// END of critical section, chunk will be lost if process gets hard terminated in between
}

template <typename ChunkDistributorType>
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/mepoo/chunk_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ struct ChunkInfo
/// @brief size of header and used payload (remaining bytes of the memory chunk are not counted)
std::uint32_t m_usedSizeOfChunk{0};

/// @brief total size of the chunk, independent of the usage
std::uint32_t m_totalSizeOfChunk{0};

TimePointNs m_txTimestamp;
};

} // namespace mepoo
} // namespace iox

6 changes: 5 additions & 1 deletion iceoryx_posh/source/mepoo/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,16 @@ SharedChunk MemoryManager::getChunk(const MaxSize_t f_size)
void* chunk{nullptr};
MemPool* memPoolPointer{nullptr};
uint32_t adjustedSize = MemoryManager::sizeWithChunkHeaderStruct(f_size);
uint32_t totalSizeOfAquiredChunk = 0;

for (auto& memPool : m_memPoolVector)
{
if (memPool.getChunkSize() >= adjustedSize)
uint32_t chunkSizeOfMemPool = memPool.getChunkSize();
if (chunkSizeOfMemPool >= adjustedSize)
{
chunk = memPool.getChunk();
memPoolPointer = &memPool;
totalSizeOfAquiredChunk = chunkSizeOfMemPool;
break;
}
}
Expand All @@ -190,6 +193,7 @@ SharedChunk MemoryManager::getChunk(const MaxSize_t f_size)
new (chunk) ChunkHeader();
static_cast<ChunkHeader*>(chunk)->m_info.m_payloadSize = f_size;
static_cast<ChunkHeader*>(chunk)->m_info.m_usedSizeOfChunk = adjustedSize;
static_cast<ChunkHeader*>(chunk)->m_info.m_totalSizeOfChunk = totalSizeOfAquiredChunk;
ChunkManagement* chunkManagement = static_cast<ChunkManagement*>(m_chunkManagementPool.front().getChunk());
new (chunkManagement)
ChunkManagement(static_cast<ChunkHeader*>(chunk), memPoolPointer, &m_chunkManagementPool.front());
Expand Down
Loading

0 comments on commit 0f6e9e3

Please sign in to comment.