Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ EventsCBGExecutor::run(
continue;
}

if(ready_entity.moreEntitiesReady) {
scheduler->unblock_one_worker_thread();
}

try {
ready_entity.entity->execute_function();
} catch (const std::exception & e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ FirstInFirstOutScheduler::get_handle_for_callback_group(

CBGScheduler::ExecutableEntityWithInfo FirstInFirstOutScheduler::get_next_ready_entity_intern()
{
std::lock_guard l(ready_callback_groups_mutex);

while(!ready_callback_groups.empty()) {
FirstInFirstOutCallbackGroupHandle *ready_cbg =
static_cast<FirstInFirstOutCallbackGroupHandle *>(ready_callback_groups.front());
Expand Down Expand Up @@ -183,8 +181,6 @@ CBGScheduler::ExecutableEntityWithInfo FirstInFirstOutScheduler::get_next_ready_
CBGScheduler::ExecutableEntityWithInfo FirstInFirstOutScheduler::get_next_ready_entity_intern(
GlobalEventIdProvider::MonotonicId max_id)
{
std::lock_guard l(ready_callback_groups_mutex);

// as, we remove an reappend ready callback_groups during execution,
// the first ready cbg may not contain the lowest id. Therefore we
// need to search the whole deque
Expand Down
40 changes: 24 additions & 16 deletions rclcpp/src/rclcpp/executors/events_cbg_executor/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ class CBGScheduler
*/
ExecutableEntityWithInfo get_next_ready_entity()
{
{
std::lock_guard l(ready_callback_groups_mutex);
if(needs_sync) {
needs_sync = false;
return ExecutableEntityWithInfo{.entity =
ExecutableEntity{.execute_function = sync_function, .callback_handle = nullptr},
.moreEntitiesReady = false};
}
std::lock_guard l(ready_callback_groups_mutex);
worker_checking_for_work = false;

if(needs_sync) {
needs_sync = false;
return ExecutableEntityWithInfo{.entity =
ExecutableEntity{.execute_function = sync_function, .callback_handle = nullptr},
.moreEntitiesReady = false};
}

return get_next_ready_entity_intern();
Expand All @@ -279,19 +279,22 @@ class CBGScheduler
ExecutableEntityWithInfo get_next_ready_entity(
GlobalEventIdProvider::MonotonicId max_id)
{
{
std::lock_guard l(ready_callback_groups_mutex);
if(needs_sync) {
needs_sync = false;
return ExecutableEntityWithInfo{.entity =
ExecutableEntity{.execute_function = sync_function, .callback_handle = nullptr},
.moreEntitiesReady = false};
}
std::lock_guard l(ready_callback_groups_mutex);
worker_checking_for_work = false;

if(needs_sync) {
needs_sync = false;
return ExecutableEntityWithInfo{.entity =
ExecutableEntity{.execute_function = sync_function, .callback_handle = nullptr},
.moreEntitiesReady = false};
}

return get_next_ready_entity_intern(max_id);
}

/**
* Will be called while holding the ready_callback_groups_mutex lock
*/
virtual ExecutableEntityWithInfo get_next_ready_entity_intern() = 0;
virtual ExecutableEntityWithInfo get_next_ready_entity_intern(
Comment on lines +295 to 299

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

now i do not explain why those virtual methods overload in FirstInFirstOutScheduler are public? before the PR, they were self-locking but now it is caller's responsibility as mentioned. how about moving both pure-virtual declarations into the protected: section (nothing outside the class hierarchy should call them)?

GlobalEventIdProvider::MonotonicId max_id) = 0;
Expand Down Expand Up @@ -338,6 +341,10 @@ class CBGScheduler
{
{
std::lock_guard lk(ready_callback_groups_mutex);
if(worker_checking_for_work) {
return;
}
worker_checking_for_work = true;
release_worker_once = true;
}
work_ready_conditional.notify_one();
Expand Down Expand Up @@ -385,6 +392,7 @@ class CBGScheduler

bool release_workers = false;
bool release_worker_once = false;
bool worker_checking_for_work = false;

std::condition_variable work_ready_conditional;

Expand Down