-
Notifications
You must be signed in to change notification settings - Fork 479
Create common structures for executors to use #2143
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2bf88de
Deprecate callback_group call taking context
mjcarroll 9099635
Add base executor objects that can be used by implementors
mjcarroll 2426056
Template common operations
mjcarroll 173ffd6
Address reviewer feedback:
mjcarroll a524bf0
Lint
mjcarroll 89f2106
Address reviewer feedback and fix templates
mjcarroll 9695eaa
Merge branch 'rolling' into mjcarroll/executor_structures
mjcarroll e173e5a
Lint and docs
mjcarroll 653d1a3
Make executor own the notify waitable
mjcarroll a6c4c1b
Add pending queue to collector, remove from waitable
mjcarroll 9dd48ce
Change interrupt guard condition to shared_ptr
mjcarroll 6267741
Lint and docs
mjcarroll 1b1a915
Don't exchange atomic twice
mjcarroll 0a9c9a6
Fix add_node and add more tests
mjcarroll 0ae0bea
Make get_notify_guard_condition follow API tick-tock
mjcarroll 87f41bf
Improve callback group tick-tocking
mjcarroll 5809328
Don't lock twice
mjcarroll debe396
Address reviewer feedback
mjcarroll c4b6589
Add thread safety annotations and make locks consistent
mjcarroll cd7aaba
Address reviewer feedback
mjcarroll 6379f0c
Remove the "add_valid_node" API
mjcarroll 855c64d
Only notify if the trigger condition is valid
mjcarroll d9a9206
Only trigger if valid and needed
mjcarroll 838d1ae
Merge branch 'rolling' into mjcarroll/executor_structures
mjcarroll ab3bbf4
Merge branch 'rolling' into mjcarroll/executor_structures
mjcarroll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
rclcpp/include/rclcpp/executors/executor_entities_collection.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright 2023 Open Source Robotics Foundation, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef RCLCPP__EXECUTORS__EXECUTOR_ENTITIES_COLLECTION_HPP_ | ||
| #define RCLCPP__EXECUTORS__EXECUTOR_ENTITIES_COLLECTION_HPP_ | ||
|
|
||
| #include <deque> | ||
mjcarroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include <rclcpp/any_executable.hpp> | ||
| #include <rclcpp/node_interfaces/node_base.hpp> | ||
| #include <rclcpp/callback_group.hpp> | ||
| #include <rclcpp/executors/executor_notify_waitable.hpp> | ||
| #include <rclcpp/visibility_control.hpp> | ||
| #include <rclcpp/wait_result.hpp> | ||
| #include <rclcpp/wait_set.hpp> | ||
|
|
||
| namespace rclcpp | ||
| { | ||
| namespace executors | ||
| { | ||
|
|
||
| template<typename EntityValueType> | ||
| struct CollectionEntry | ||
| { | ||
| typename EntityValueType::WeakPtr entity; | ||
| rclcpp::CallbackGroup::WeakPtr callback_group; | ||
| }; | ||
|
|
||
| template<typename CollectionType> | ||
| void update_entities( | ||
| const CollectionType & update_from, | ||
| CollectionType update_to, | ||
| std::function<void(typename CollectionType::mapped_type::EntitySharedPtr)> on_added, | ||
| std::function<void(typename CollectionType::mapped_type::EntitySharedPtr)> on_removed | ||
| ) | ||
| { | ||
| for (auto it = update_to.begin(); it != update_to.end(); ) { | ||
| if (update_from.count(it->first) == 0) { | ||
| auto entity = it->second.entity.lock(); | ||
| if (entity) { | ||
| on_removed(entity); | ||
| } | ||
| it = update_to.erase(it); | ||
| } else { | ||
| ++it; | ||
| } | ||
| } | ||
| for (auto it = update_from.begin(); it != update_from.end(); ++it) { | ||
| if (update_to.count(it->first) == 0) { | ||
| auto entity = it->entity.lock(); | ||
| if (entity) { | ||
| on_added(entity); | ||
| } | ||
| update_to.insert(*it); | ||
| } | ||
| } | ||
| } | ||
mjcarroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| template<typename EntityKeyType, typename EntityValueType> | ||
| class EntityCollection | ||
| : public std::unordered_map<const EntityKeyType *, CollectionEntry<EntityValueType>> | ||
| { | ||
| public: | ||
| using Key = const EntityKeyType *; | ||
| using EntityWeakPtr = typename EntityValueType::WeakPtr; | ||
| using EntitySharedPtr = typename EntityValueType::SharedPtr; | ||
|
|
||
| void update( | ||
| const EntityCollection<EntityKeyType, EntityValueType> & other, | ||
| std::function<void(EntitySharedPtr)> on_added, | ||
| std::function<void(EntitySharedPtr)> on_removed) | ||
| { | ||
| update_entities(*this, other, on_added, on_removed); | ||
| } | ||
| }; | ||
|
|
||
| /// Represent the total set of entities for a single executor | ||
| /** | ||
| * This allows the entities to be stored from ExecutorEntitiesCollector. | ||
| * The structure also makes in convenient to re-evaluate when entities have been added or removed. | ||
| */ | ||
| struct ExecutorEntitiesCollection | ||
| { | ||
| /// Entity entries for timers | ||
| using TimerCollection = EntityCollection<rcl_timer_t, rclcpp::TimerBase>; | ||
|
|
||
| /// Entity entries for subscriptions | ||
| using SubscriptionCollection = EntityCollection<rcl_subscription_t, rclcpp::SubscriptionBase>; | ||
|
|
||
| /// Entity entries for clients | ||
| using ClientCollection = EntityCollection<rcl_client_t, rclcpp::ClientBase>; | ||
|
|
||
| /// Entity entries for services | ||
| using ServiceCollection = EntityCollection<rcl_service_t, rclcpp::ServiceBase>; | ||
|
|
||
| /// Entity entries for waitables | ||
| using WaitableCollection = EntityCollection<rclcpp::Waitable, rclcpp::Waitable>; | ||
|
|
||
| /// Entity entries for guard conditions | ||
| using GuardConditionCollection = EntityCollection<rcl_guard_condition_t, rclcpp::GuardCondition>; | ||
|
|
||
| TimerCollection timers; | ||
| SubscriptionCollection subscriptions; | ||
| ClientCollection clients; | ||
| ServiceCollection services; | ||
| GuardConditionCollection guard_conditions; | ||
| WaitableCollection waitables; | ||
|
|
||
| void clear(); | ||
| }; | ||
|
|
||
| void | ||
| build_entities_collection( | ||
| const std::vector<rclcpp::CallbackGroup::WeakPtr> & callback_groups, | ||
| ExecutorEntitiesCollection & collection); | ||
|
|
||
| std::deque<rclcpp::AnyExecutable> | ||
| ready_executables( | ||
| const ExecutorEntitiesCollection & collection, | ||
| rclcpp::WaitResult<rclcpp::WaitSet> & wait_result | ||
| ); | ||
|
|
||
| } // namespace executors | ||
| } // namespace rclcpp | ||
|
|
||
| #endif // RCLCPP__EXECUTORS__EXECUTOR_ENTITIES_COLLECTION_HPP_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.