Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Sep 17, 2023
1 parent 77efd2a commit 24a84b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tesseract_task_composer/core/src/task_composer_node_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ TaskComposerNodeInfoContainer::TaskComposerNodeInfoContainer(const TaskComposerN
std::shared_lock rhs_lock(other.mutex_, std::defer_lock);
std::scoped_lock lock{ lhs_lock, rhs_lock };

*this = other;
aborting_node_ = other.aborting_node_;
for (const auto& pair : other.info_map_)
info_map_[pair.first] = pair.second->clone();
}
TaskComposerNodeInfoContainer& TaskComposerNodeInfoContainer::operator=(const TaskComposerNodeInfoContainer& other)
{
std::unique_lock lhs_lock(mutex_, std::defer_lock);
std::shared_lock rhs_lock(other.mutex_, std::defer_lock);
std::scoped_lock lock{ lhs_lock, rhs_lock };

aborting_node_ = other.aborting_node_;
for (const auto& pair : other.info_map_)
info_map_[pair.first] = pair.second->clone();

Expand All @@ -123,14 +126,16 @@ TaskComposerNodeInfoContainer::TaskComposerNodeInfoContainer(TaskComposerNodeInf
std::unique_lock rhs_lock(other.mutex_, std::defer_lock);
std::scoped_lock lock{ lhs_lock, rhs_lock };

*this = std::move(other);
aborting_node_ = other.aborting_node_;
info_map_ = std::move(other.info_map_);
}
TaskComposerNodeInfoContainer& TaskComposerNodeInfoContainer::operator=(TaskComposerNodeInfoContainer&& other) noexcept
{
std::unique_lock lhs_lock(mutex_, std::defer_lock);
std::unique_lock rhs_lock(other.mutex_, std::defer_lock);
std::scoped_lock lock{ lhs_lock, rhs_lock };

aborting_node_ = other.aborting_node_;
info_map_ = std::move(other.info_map_);

return *this;
Expand Down Expand Up @@ -252,6 +257,7 @@ template <class Archive>
void TaskComposerNodeInfoContainer::serialize(Archive& ar, const unsigned int /*version*/)
{
std::unique_lock<std::shared_mutex> lock(mutex_);
ar& BOOST_SERIALIZATION_NVP(aborting_node_);
ar& BOOST_SERIALIZATION_NVP(info_map_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ TEST(TesseractTaskComposerCoreUnit, TaskComposerNodeInfoContainerTests) // NOLI
auto node_info = std::make_unique<TaskComposerNodeInfo>(node);

auto node_info_container = std::make_unique<TaskComposerNodeInfoContainer>();
EXPECT_TRUE(node_info_container->getAbortingNode().is_nil());
EXPECT_TRUE(node_info_container->getInfoMap().empty());
auto aborted_uuid = node.getUUID();
node_info_container->addInfo(std::move(node_info));
node_info_container->setAborted(aborted_uuid);
EXPECT_EQ(node_info_container->getInfoMap().size(), 1);
EXPECT_TRUE(node_info_container->getInfo(node.getUUID()) != nullptr);
EXPECT_TRUE(node_info_container->getAbortingNode() == aborted_uuid);

// Serialization
test_suite::runSerializationPointerTest(node_info_container, "TaskComposerNodeInfoContainerTests");
Expand All @@ -180,15 +184,18 @@ TEST(TesseractTaskComposerCoreUnit, TaskComposerNodeInfoContainerTests) // NOLI
auto copy_node_info_container = std::make_unique<TaskComposerNodeInfoContainer>(*node_info_container);
EXPECT_EQ(copy_node_info_container->getInfoMap().size(), 1);
EXPECT_TRUE(copy_node_info_container->getInfo(node.getUUID()) != nullptr);
EXPECT_TRUE(copy_node_info_container->getAbortingNode() == aborted_uuid);

// Move
auto move_node_info_container = std::make_unique<TaskComposerNodeInfoContainer>(std::move(*node_info_container));
EXPECT_EQ(move_node_info_container->getInfoMap().size(), 1);
EXPECT_TRUE(move_node_info_container->getInfo(node.getUUID()) != nullptr);
EXPECT_TRUE(move_node_info_container->getAbortingNode() == aborted_uuid);

move_node_info_container->clear();
EXPECT_TRUE(move_node_info_container->getInfoMap().empty());
EXPECT_TRUE(move_node_info_container->getInfo(node.getUUID()) == nullptr);
EXPECT_TRUE(move_node_info_container->getAbortingNode().is_nil());
}

TEST(TesseractTaskComposerCoreUnit, TaskComposerNodeTests) // NOLINT
Expand Down

0 comments on commit 24a84b1

Please sign in to comment.