Skip to content

Commit

Permalink
iox-#859 Move typed allocator to iox::memory
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
  • Loading branch information
MatthiasKillat committed Jan 31, 2022
1 parent ad29966 commit 0dc4e56
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_DATA_STRUCTURES_PREFIX_TREE_HPP
#define IOX_HOOFS_DATA_STRUCTURES_PREFIX_TREE_HPP
#ifndef IOX_HOOFS_CXX_PREFIX_TREE_HPP
#define IOX_HOOFS_CXX_PREFIX_TREE_HPP

#include <iostream>
#include <stdint.h>
#include <string>
#include <vector>

#include "iceoryx_hoofs/cxx/string.hpp"
#include "iceoryx_hoofs/cxx/vector.hpp"
#include "iceoryx_hoofs/data_structures/typed_allocator.hpp"
#include "iceoryx_hoofs/internal/relocatable_pointer/relocatable_ptr.hpp"
#include "iceoryx_hoofs/memory/typed_allocator.hpp"

namespace iox
{
Expand Down Expand Up @@ -224,8 +221,8 @@ class PrefixTree
// suitable external allocators.
// The allocators can allocate enough nodes to support the specified capacity.

using NodeAllocator = iox::cxx::TypedAllocator<Node, NUMBER_OF_ALLOCATABLE_NODES>;
using DataNodeAllocator = iox::cxx::TypedAllocator<DataNode, Capacity>;
using NodeAllocator = iox::memory::TypedAllocator<Node, NUMBER_OF_ALLOCATABLE_NODES>;
using DataNodeAllocator = iox::memory::TypedAllocator<DataNode, Capacity>;

DataNodeAllocator m_dataNodeAllocator;
NodeAllocator m_nodeAllocator;
Expand Down Expand Up @@ -287,7 +284,7 @@ class PrefixTree
} // namespace cxx
} // namespace iox

#include "iceoryx_hoofs/data_structures/prefix_tree.inl"
#include "iceoryx_hoofs/internal/cxx/prefix_tree.inl"


#endif // IOX_HOOFS_DATA_STRUCTURES_PREFIX_TREE_HPP
#endif // IOX_HOOFS_CXX_PREFIX_TREE_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/data_structures/prefix_tree.hpp"
#ifndef IOX_HOOFS_CXX_PREFIX_TREE_INL
#define IOX_HOOFS_CXX_PREFIX_TREE_INL

#include "iceoryx_hoofs/cxx/prefix_tree.hpp"

namespace iox
{
Expand Down Expand Up @@ -717,5 +720,6 @@ void PrefixTree<Value, Capacity, MaxKeyLength>::getPairs(Node* node,
}

} // namespace cxx

} // namespace iox

#endif // IOX_HOOFS_CXX_PREFIX_TREE_INL
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_DATA_STRUCTURES_TYPED_ALLOCATOR_INL
#define IOX_HOOFS_DATA_STRUCTURES_TYPED_ALLOCATOR_INL
#ifndef IOX_HOOFS_MEMORY_TYPED_ALLOCATOR_INL
#define IOX_HOOFS_MEMORY_TYPED_ALLOCATOR_INL

#include "iceoryx_hoofs/data_structures/typed_allocator.hpp"
#include "iceoryx_hoofs/memory/typed_allocator.hpp"

#include <stdint.h>

namespace iox
{
namespace cxx
namespace memory
{
template <typename T, uint64_t Capacity>
T* iox::cxx::TypedAllocator<T, Capacity>::allocate()
T* TypedAllocator<T, Capacity>::allocate()
{
auto maybeIndex = m_freeIndices.pop();
if (maybeIndex.has_value())
Expand All @@ -37,7 +37,7 @@ T* iox::cxx::TypedAllocator<T, Capacity>::allocate()
}

template <typename T, uint64_t Capacity>
void iox::cxx::TypedAllocator<T, Capacity>::deallocate(T* element)
void TypedAllocator<T, Capacity>::deallocate(T* element)
{
// no checking whether this is a pointer allocated by this allocator (
// (not possible without serious overhead)
Expand All @@ -46,7 +46,7 @@ void iox::cxx::TypedAllocator<T, Capacity>::deallocate(T* element)

template <typename T, uint64_t Capacity>
template <typename... Args>
T* iox::cxx::TypedAllocator<T, Capacity>::create(Args&&... args)
T* TypedAllocator<T, Capacity>::create(Args&&... args)
{
auto element = allocate();
if (element)
Expand All @@ -58,7 +58,7 @@ T* iox::cxx::TypedAllocator<T, Capacity>::create(Args&&... args)
}

template <typename T, uint64_t Capacity>
void iox::cxx::TypedAllocator<T, Capacity>::destroy(T* element)
void TypedAllocator<T, Capacity>::destroy(T* element)
{
if (element)
{
Expand All @@ -67,7 +67,7 @@ void iox::cxx::TypedAllocator<T, Capacity>::destroy(T* element)
}
}

} // namespace cxx
} // namespace memory
} // namespace iox

#endif IOX_HOOFS_DATA_STRUCTURES_TYPED_ALLOCATOR_INL
#endif // IOX_HOOFS_MEMORY_TYPED_ALLOCATOR_INL
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_DATA_STRUCTURES_TYPED_ALLOCATOR_HPP
#define IOX_HOOFS_DATA_STRUCTURES_TYPED_ALLOCATOR_HPP
#ifndef IOX_HOOFS_MEMORY_TYPED_ALLOCATOR_HPP
#define IOX_HOOFS_MEMORY_TYPED_ALLOCATOR_HPP

#include <stdint.h>

#include "iceoryx_hoofs/internal/concurrent/lockfree_queue/index_queue.hpp"

namespace iox
{
namespace cxx
namespace memory
{
/// @brief An allocator for objects of a specific type T.
/// Supports allocation of initialized objects and aligned raw memory where objects
Expand Down Expand Up @@ -104,9 +104,9 @@ class TypedAllocator
}
};

} // namespace cxx
} // namespace memory
} // namespace iox

#include "iceoryx_hoofs/data_structures/typed_allocator.inl"
#include "iceoryx_hoofs/internal/memory/typed_allocator.inl"

#endif // IOX_HOOFS_DATA_STRUCTURES_TYPED_ALLOCATOR_HPP
#endif // IOX_HOOFS_MEMORY_TYPED_ALLOCATOR_HPP
2 changes: 1 addition & 1 deletion iceoryx_hoofs/test/moduletests/test_prefix_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "test.hpp"

#include "iceoryx_hoofs/data_structures/prefix_tree.hpp"
#include "iceoryx_hoofs/cxx/prefix_tree.hpp"

#include <set>
#include <vector>
Expand Down
6 changes: 4 additions & 2 deletions iceoryx_hoofs/test/moduletests/test_typed_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "test.hpp"

#include "iceoryx_hoofs/data_structures/typed_allocator.hpp"
#include "iceoryx_hoofs/memory/typed_allocator.hpp"

#include <algorithm>
#include <vector>
Expand All @@ -25,7 +25,7 @@ namespace
{
using namespace ::testing;

using namespace iox::cxx;
using namespace iox::memory;

// count #ctor and #dtor calls
template <typename T>
Expand Down Expand Up @@ -302,5 +302,7 @@ TEST_F(TypedAllocator_test, CreatedElementsHaveUniqueAdresses)
}
}

// todo: relocation test


} // namespace

0 comments on commit 0dc4e56

Please sign in to comment.