@@ -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 }
0 commit comments