Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1036 Baseaddress as optional ctor argument
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <me@elchris.org>
  • Loading branch information
elfenpiff committed Jan 25, 2022
1 parent c55a172 commit 6d3c7eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
14 changes: 7 additions & 7 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/helplets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,6 @@ constexpr T into(const F value) noexcept;
/// class MyBuilder {
/// IOX_BUILDER_PARAMETER(TypeA, NameB, ValueC)
/// // START generates the following code
/// private:
/// TypeA m_NameB = ValueC;
///
/// public:
/// decltype(auto) NameB(TypeA const& value) &&
/// {
Expand All @@ -358,13 +355,13 @@ constexpr T into(const F value) noexcept;
/// m_NameB = std::move(value);
/// return std::move(*this);
/// }
///
/// private:
/// TypeA m_NameB = ValueC;
/// // END
/// };
/// @endcode
#define IOX_BUILDER_PARAMETER(type, name, defaultValue) \
private: \
type m_##name = defaultValue; \
\
public: \
decltype(auto) name(type const& value)&& \
{ \
Expand All @@ -376,7 +373,10 @@ constexpr T into(const F value) noexcept;
{ \
m_##name = std::move(value); \
return std::move(*this); \
}
} \
\
private: \
type m_##name = defaultValue;


} // namespace cxx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SharedMemoryObject : public DesignPattern::Creation<SharedMemoryObject, Sh
const uint64_t memorySizeInBytes,
const AccessMode accessMode,
const OpenMode openMode,
const void* const baseAddressHint,
const cxx::optional<const void*>& baseAddressHint = cxx::nullopt,
const mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) noexcept;

bool isInitialized() const noexcept;
Expand Down
19 changes: 13 additions & 6 deletions iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SharedMemoryObject::SharedMemoryObject(const SharedMemory::Name_t& name,
const uint64_t memorySizeInBytes,
const AccessMode accessMode,
const OpenMode openMode,
const void* const baseAddressHint,
const cxx::optional<const void*>& baseAddressHint,
const mode_t permissions) noexcept
: m_memorySizeInBytes(cxx::align(memorySizeInBytes, Allocator::MEMORY_ALIGNMENT))
{
Expand All @@ -69,7 +69,7 @@ SharedMemoryObject::SharedMemoryObject(const SharedMemory::Name_t& name,
if (m_isInitialized)
{
MemoryMapBuilder()
.baseAddressHint(baseAddressHint)
.baseAddressHint((baseAddressHint) ? *baseAddressHint : nullptr)
.length(memorySizeInBytes)
.fileDescriptor(m_sharedMemory->getHandle())
.accessMode(accessMode)
Expand All @@ -90,9 +90,16 @@ SharedMemoryObject::SharedMemoryObject(const SharedMemory::Name_t& name,
std::cerr << "Unable to create a shared memory object with the following properties [ name = " << name
<< ", sizeInBytes = " << memorySizeInBytes
<< ", access mode = " << ACCESS_MODE_STRING[static_cast<uint64_t>(accessMode)]
<< ", open mode = " << OPEN_MODE_STRING[static_cast<uint64_t>(openMode)]
<< ", baseAddressHint = " << std::hex << baseAddressHint << std::dec
<< ", permissions = " << std::bitset<sizeof(mode_t)>(permissions) << " ]" << std::endl;
<< ", open mode = " << OPEN_MODE_STRING[static_cast<uint64_t>(openMode)] << ", baseAddressHint = ";
if (baseAddressHint)
{
std::cerr << std::hex << *baseAddressHint << std::dec;
}
else
{
std::cerr << "no hint set";
}
std::cerr << ", permissions = " << std::bitset<sizeof(mode_t)>(permissions) << " ]" << std::endl;
std::cerr.setf(flags);
return;
}
Expand Down Expand Up @@ -120,7 +127,7 @@ SharedMemoryObject::SharedMemoryObject(const SharedMemory::Name_t& name,
static_cast<unsigned long long>(memorySizeInBytes),
ACCESS_MODE_STRING[static_cast<uint64_t>(accessMode)],
OPEN_MODE_STRING[static_cast<uint64_t>(openMode)],
baseAddressHint,
*baseAddressHint,
std::bitset<sizeof(mode_t)>(permissions).to_ulong());

memset(m_memoryMap->getBaseAddress(), 0, m_memorySizeInBytes);
Expand Down

0 comments on commit 6d3c7eb

Please sign in to comment.