Skip to content

Convert Clock to use a C++ Class - #749

Merged
sloretz merged 4 commits into
masterfrom
ahcorde/pybind-clock_ontop
Apr 2, 2021
Merged

sloretz merged 4 commits into
masterfrom
ahcorde/pybind-clock_ontop

Conversation

@ahcorde

@ahcorde ahcorde commented Apr 1, 2021

Copy link
Copy Markdown
Contributor

This PR builds on top of this other PR #745

Related to #665

This converts the Clock functions to a C++ class.

Signed-off-by: ahcorde [email protected]

@ahcorde
ahcorde requested a review from sloretz April 1, 2021 15:48
@ahcorde ahcorde mentioned this pull request Apr 1, 2021
32 of 34 tasks
Comment thread rclpy/CMakeLists.txt Resolved
Comment thread rclpy/rclpy/clock.py Resolved
Comment thread rclpy/rclpy/clock.py Resolved
Comment thread rclpy/src/rclpy/_rclpy_action.cpp Resolved
Comment thread rclpy/src/rclpy/clock.cpp Resolved
Comment thread rclpy/src/rclpy/clock.hpp Resolved
Comment thread rclpy/src/rclpy/timer.cpp Resolved
Comment thread rclpy/src/rclpy/timer.cpp Outdated
py::object pyclock, py::capsule pycontext, int64_t period_nsec)
{
auto clock = clock_handle_->cast<rcl_clock_t *>("rcl_clock_t");
clock_handle_ = std::make_shared<rcl_clock_t>(*pyclock.cast<Clock>().rcl_ptr());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I looks like this is creating a copy of the clock, but I don't think that's desired. If the original copy of the clock goes out of scope, then the clock will be fini()'d, and the jump callback pointers on the rcl_clock_t itself will point to free'd memory.

Instead, I think Clock should have a method that returns an std::shared_ptr<rcl_clock_t>, maybe

std::shared_ptr<rcl_clock_t>
rcl_shared_ptr()
{
    return rcl_clock_
}

and then Timer can store that with : clock_handle_(clock.rcl_shared_ptr())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ahcorde mind addressing this comment?

Comment thread rclpy/src/rclpy/timer.cpp Resolved
@delete-merged-branch
delete-merged-branch Bot deleted the branch master April 2, 2021 14:57
@ahcorde
ahcorde force-pushed the ahcorde/pybind-clock_ontop branch from b2b2fc2 to ce9fa8b Compare April 2, 2021 15:57
@ahcorde
ahcorde changed the base branch from ahcorde/pybind-timer to master April 2, 2021 15:59
@ahcorde
ahcorde requested a review from sloretz April 2, 2021 15:59
@ahcorde

ahcorde commented Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

CI (build: --packages-above-and-dependencies rclpy test: --packages-above rclpy)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@ahcorde

ahcorde commented Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

CI (build: --packages-above-and-dependencies rclpy test: --packages-above rclpy)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz

sloretz commented Apr 2, 2021

Copy link
Copy Markdown
Contributor

CI LGTM, both windows CMake warnings are in cyclonedds. Merging 🎉

@sloretz
sloretz merged commit 9c1b80a into master Apr 2, 2021
@delete-merged-branch
delete-merged-branch Bot deleted the ahcorde/pybind-clock_ontop branch April 2, 2021 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants