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

Prevent instantiation of std::vectors in wait_for_work #65

Closed
wants to merge 13 commits into from

Conversation

jacquelinekay
Copy link
Contributor

For real-time performance completeness, there should be an alternative to instantiating and allocating dynamically sized data structures in Executor::wait_for_work, even if they contain small objects like shared pointers. This pull request abstracts out the vectors instantiated in wait_for_work and replaces them with a SharedPtrContainer interface. In the default memory strategy, this interface is implemented with a std::vector, and in the StaticMemoryStrategy, it is implemented with a std::array.

@jacquelinekay jacquelinekay added the in progress Actively being worked on (Kanban column) label Jul 24, 2015
@jacquelinekay jacquelinekay self-assigned this Jul 24, 2015
@jacquelinekay jacquelinekay changed the title Prevent instantiation of std::vectors in wait_for_work Alternative to instantiating std::vectors in wait_for_work Jul 24, 2015
@jacquelinekay jacquelinekay changed the title Alternative to instantiating std::vectors in wait_for_work Prevent instantiation of std::vectors in wait_for_work Jul 24, 2015
@jacquelinekay jacquelinekay added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jul 24, 2015
@tfoote
Copy link
Contributor

tfoote commented Jul 30, 2015

+1, though there is a merge conflict now

@dirk-thomas
Copy link
Member

The referenced CI jobs also indicate new warnings.

@esteve
Copy link
Member

esteve commented Jul 30, 2015

+1

@jacquelinekay
Copy link
Contributor Author

CI after rebase and warnings fix:

Linux and OSX green, no new warnings on Windows
http://ci.ros2.org/job/ros2_batch_ci_linux/119/
http://ci.ros2.org/job/ros2_batch_ci_osx/61/
http://ci.ros2.org/job/ros2_batch_ci_windows/88/

@dirk-thomas
Copy link
Member

The two warning categories (C4996 and MSB3073) on Windows are currently also the case when building the master: see http://ci.ros2.org/job/ros2_batch_ci_windows/86/

@jacquelinekay
Copy link
Contributor Author

Going to squash and merge if that's ok.

@dirk-thomas
Copy link
Member

The SharedPtrContainer class seems to be essentially a std::vector and the StaticSharedPtrContainer a std::array. Instead of implementing our own base class as well as two subclasses would it be possible to just provide typedefs to the specific std storage classes and use them with there already existing identical API?

@jacquelinekay
Copy link
Contributor Author

yes, a much "slimmer" solution is possible. I will investigate it.

@jacquelinekay jacquelinekay added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Jul 31, 2015
@jacquelinekay
Copy link
Contributor Author

The definitions for the different storage classes cannot be typedefs because typedefs cannot be templated (unless a different typedef is to be defined for each necessary template specialization of array, vector, etc). Perhaps a type alias is preferable.

However, the API for the two storage containers is not identical because std::array does not have push_back. The container class in this PR implements push_back for the static container, which causes the std::array to behave like a ring buffer. Because the APIs are not identical, I actually don't think a typedef or a type alias is a good idea.

Another detail I'm not clear on is how to override the definition made in MemoryStrategy (e.g. ContainerType -> std::vector) in StaticMemoryStrategy (ContainerType<T, Size> -> std::array<T, Size>), which is a subclass ofMemoryStrategy`.

Perhaps I should simply implement or find a ring buffer class with an identical (or similar) API to std::vector (since there is no std::ring_buffer) and then follow your original suggestion to provide a definition in Executor (ContainerType) that defaults to std::vector but can be overridden to the new ring buffer type.

That way, future changes to rclcpp that instantiate a vector-like container can be real-time safe.

@jacquelinekay
Copy link
Contributor Author

After some discussion offline I've decided to close this PR and readdress the problem of implementing static/real-time safe alternatives to std::vector, std::map and std::string after further testing of rclcpp.

@jacquelinekay jacquelinekay removed the in progress Actively being worked on (Kanban column) label Aug 7, 2015
@jacquelinekay jacquelinekay deleted the stl_roundup branch September 8, 2015 22:36
mauropasse pushed a commit to mauropasse/rclcpp that referenced this pull request May 24, 2021
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
* ros2GH-23 Get all topics from node and sanitize

* ros2GH-23 Move methods to node for better interface

* ros2GH-23 Use rmw_serialized_message_t consistently

* ros2GH-23 Improve santization of topics

* ros2GH-65 Introduce and use better logging macros

* ros2GH-23 Use publisher to serialized message directly

* ros2GH-23 Improve readability of sanitizing topics and types

* ros2GH-23 Allow to write all available topics

* ros2GH-23 Add test for record all

* ros2GH-23 Cleanup: add missing const ref to record interface

* Cleanup for doxygen

* Improve topic sanitization

- correctly expand topic names using rcl
- do not check type correctness (supposed to be done internally)

* Pass topic_name by reference
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
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.

4 participants