Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nav2_costmap_2d] add the std::unique_lock before layered_costmap->isCurrent() #3958

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fc4103f
image.hpp #3891
GoesM Oct 24, 2023
45f7de6
Update image.hpp
GoesM Oct 24, 2023
33ca045
Merge branch 'ros-planning:main' into main
GoesM Oct 28, 2023
93515e6
Update costmap_2d_ros.hpp
GoesM Nov 11, 2023
fc58f3d
Merge branch 'ros-planning:main' into main
GoesM Nov 12, 2023
590754d
uncrustify costmap_2d_ros.hpp
GoesM Nov 12, 2023
8e6c49d
Update costmap_2d_ros.hpp
GoesM Nov 12, 2023
0144fcb
Update costmap_2d_ros.cpp
GoesM Nov 12, 2023
913b62f
Update costmap_2d.cpp
GoesM Nov 12, 2023
ed037ce
Update costmap_2d_ros.cpp
GoesM Nov 12, 2023
fc27c4e
Update costmap_2d_ros.hpp
GoesM Nov 12, 2023
41936a3
add UAF_lock into isCurrent
GoesM Nov 12, 2023
fe1ffb9
Update costmap_2d_ros.cpp
GoesM Nov 12, 2023
b3e6d0e
Update costmap_2d_ros.cpp
GoesM Nov 12, 2023
63aadd0
add free_access_ lock only for UAF check
GoesM Nov 12, 2023
5ffc636
add free_access_ lock only for UAF check
GoesM Nov 12, 2023
1d1ba61
Add files via upload
GoesM Nov 12, 2023
b2884d6
Add files via upload
GoesM Nov 12, 2023
1a68938
Add files via upload
GoesM Nov 12, 2023
cc218a4
Add files via upload
GoesM Nov 12, 2023
21269dc
Add files via upload
GoesM Nov 12, 2023
9cdd4e2
add lock
GoesM Nov 13, 2023
1b75741
add lock
GoesM Nov 13, 2023
da50098
add lock
GoesM Nov 13, 2023
99ba7af
add lock
GoesM Nov 13, 2023
5a6f0cd
add the lock
GoesM Nov 13, 2023
0123e3e
add lock
GoesM Nov 13, 2023
4ffd4ca
add lock
GoesM Nov 13, 2023
e6c3471
Merge pull request #1 from GoesM/GoesM-patch-1
GoesM Nov 13, 2023
c7ffad9
add lock
GoesM Nov 13, 2023
411dca6
Update costmap_2d_ros.hpp
GoesM Nov 14, 2023
feba489
Update costmap_2d_ros.cpp
GoesM Nov 14, 2023
f815739
add lock
GoesM Nov 14, 2023
0f5c90d
new
Nov 14, 2023
0f2a906
conflict solvedf
Nov 14, 2023
e4e5e97
Merge pull request #3 from GoesM/GoesM-patch-1
GoesM Nov 14, 2023
bf95177
Update nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_ros.hpp
GoesM Nov 16, 2023
066294a
Update costmap_2d_ros.cpp
GoesM Nov 16, 2023
e119c3d
Merge branch 'ros-planning:main' into main
GoesM Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_ros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ class Costmap2DROS : public nav2_util::LifecycleNode
/** @brief Same as getLayeredCostmap()->isCurrent(). */
bool isCurrent()
{
//lock because no ptr-access is allowed until other ptr-free finished
std::unique_lock<Costmap2D::mutex_t> lock(*access_);
if (layered_costmap_ == nullptr) {
return false; // to avoid nullptr accessed
}
return layered_costmap_->isCurrent();
}

Expand Down Expand Up @@ -316,6 +321,13 @@ class Costmap2DROS : public nav2_util::LifecycleNode
*/
double getRobotRadius() {return robot_radius_;}

// Provide a typedef to ease future code maintenance
typedef std::recursive_mutex mutex_t;
mutex_t * getMutex()
{
return access_;
}

protected:
// Publishers and subscribers
rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::PolygonStamped>::SharedPtr
Expand Down Expand Up @@ -397,6 +409,9 @@ class Costmap2DROS : public nav2_util::LifecycleNode
*/
rcl_interfaces::msg::SetParametersResult
dynamicParametersCallback(std::vector<rclcpp::Parameter> parameters);

private:
mutex_t * access_;
};

} // namespace nav2_costmap_2d
Expand Down
7 changes: 7 additions & 0 deletions nav2_costmap_2d/src/costmap_2d_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ void Costmap2DROS::init()
declare_parameter("update_frequency", rclcpp::ParameterValue(5.0));
declare_parameter("use_maximum", rclcpp::ParameterValue(false));
declare_parameter("clearable_layers", rclcpp::ParameterValue(clearable_layers));

access_ = new mutex_t();
}

Costmap2DROS::~Costmap2DROS()
{
delete access_;
}

nav2_util::CallbackReturn
Expand Down Expand Up @@ -360,6 +363,8 @@ Costmap2DROS::on_cleanup(const rclcpp_lifecycle::State & /*state*/)

layer_publishers_.clear();

//lock because no ptr-access is allowed until this ptr-free finished
std::unique_lock<Costmap2D::mutex_t> lock(*access_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anywhere else we should be locking the layered_costmap_ as well?

layered_costmap_.reset();

tf_listener_.reset();
Expand All @@ -370,6 +375,8 @@ Costmap2DROS::on_cleanup(const rclcpp_lifecycle::State & /*state*/)


executor_thread_.reset();

lock.unlock();
return nav2_util::CallbackReturn::SUCCESS;
}

Expand Down