Skip to content

Commit e650b79

Browse files
author
Minggang Wang
committed
Fix the compiling failure due to rcl changes
Fix #413
1 parent 4fa2c26 commit e650b79

File tree

2 files changed

+23
-51
lines changed

2 files changed

+23
-51
lines changed

src/executor.cpp

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,21 @@ void Executor::Run(void* arg) {
105105

106106
{
107107
ScopedMutex mutex(handle_manager->mutex());
108-
if (rcl_wait_set_resize_subscriptions(
109-
&wait_set, handle_manager->subscription_count()) !=
110-
RCL_RET_OK) {
111-
throw std::runtime_error(
112-
std::string(
113-
"Couldn't resize the number of subscriptions in waitset : ") +
114-
rcl_get_error_string_safe());
115-
}
116-
117-
if (rcl_wait_set_resize_services(
118-
&wait_set, handle_manager->service_count()) != RCL_RET_OK) {
119-
throw std::runtime_error(
120-
std::string(
121-
"Couldn't resize the number of services in waitset : ") +
122-
rcl_get_error_string_safe());
123-
}
124-
125-
if (rcl_wait_set_resize_clients(
126-
&wait_set, handle_manager->client_count()) != RCL_RET_OK) {
127-
throw std::runtime_error(
128-
std::string(
129-
"Couldn't resize the number of clients in waitset : ") +
130-
rcl_get_error_string_safe());
131-
}
132-
133-
if (rcl_wait_set_resize_timers(
134-
&wait_set, handle_manager->timer_count()) != RCL_RET_OK) {
135-
throw std::runtime_error(
136-
std::string(
137-
"Couldn't resize the number of timers in waitset : ") +
138-
rcl_get_error_string_safe());
139-
}
108+
if (handle_manager->is_empty())
109+
continue;
110+
111+
if (rcl_wait_set_resize(
112+
&wait_set,
113+
handle_manager->subscription_count(),
114+
// TODO(minggang): support guard conditions
115+
0u,
116+
handle_manager->timer_count(),
117+
handle_manager->client_count(),
118+
handle_manager->service_count()) != RCL_RET_OK) {
119+
std::string error_message = std::string("Failed to resize: ")
120+
+ std::string(rcl_get_error_string_safe());
121+
throw std::runtime_error(error_message);
122+
}
140123

141124
if (!handle_manager->AddHandlesToWaitSet(&wait_set)) {
142125
throw std::runtime_error("Couldn't fill waitset");
@@ -154,25 +137,10 @@ void Executor::Run(void* arg) {
154137
}
155138
}
156139

157-
if (rcl_wait_set_clear_subscriptions(&wait_set) != RCL_RET_OK) {
158-
throw std::runtime_error("Couldn't clear subscriptions from waitset");
159-
}
160-
161-
if (rcl_wait_set_clear_services(&wait_set) != RCL_RET_OK) {
162-
throw std::runtime_error("Couldn't clear servicess from waitset");
163-
}
164-
165-
if (rcl_wait_set_clear_clients(&wait_set) != RCL_RET_OK) {
166-
throw std::runtime_error("Couldn't clear clients from waitset");
167-
}
168-
169-
if (rcl_wait_set_clear_guard_conditions(&wait_set) != RCL_RET_OK) {
170-
throw std::runtime_error(
171-
"Couldn't clear guard conditions from waitset");
172-
}
173-
174-
if (rcl_wait_set_clear_timers(&wait_set) != RCL_RET_OK) {
175-
throw std::runtime_error("Couldn't clear timers from waitset");
140+
if (rcl_wait_set_clear(&wait_set) != RCL_RET_OK) {
141+
std::string error_message = std::string("Failed to clear wait set: ")
142+
+ std::string(rcl_get_error_string_safe());
143+
throw std::runtime_error(error_message);
176144
}
177145
}
178146
}

src/handle_manager.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class HandleManager {
4848
uint32_t timer_count() const { return timers_.size(); }
4949
uv_mutex_t* mutex() { return &mutex_; }
5050
bool is_synchronizing() const { return is_synchronizing_.load(); }
51+
bool is_empty() const { return subscriptions_.size() == 0
52+
&& services_.size() == 0
53+
&& clients_.size() == 0
54+
&& timers_.size() == 0; }
5155

5256
protected:
5357
template<typename T> void CollectHandlesByType(

0 commit comments

Comments
 (0)