Repository navigation
Add function for waiting on multiple wait sets together - #330
jacobperron wants to merge 9 commits into
Conversation
Internally, the function collates all wait sets into a single wait set that is waited on.
hidmic
left a comment
There was a problem hiding this comment.
Looking good! Left a few comments.
|
|
||
| /// Block until multiple wait sets are ready or until the timeout has been exceeded. | ||
| /** | ||
| * This function has similar behavior as rcl_wait(), but acts on multiple wait sets. |
| } | ||
|
|
||
| // Test rcl_wait_multiple with a positive finite timeout value (1ms) | ||
| TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), finite_timeout_multiple) { |
There was a problem hiding this comment.
@jacobperron shouldn't we add a few more tests? Like, for negative timeout, for zero timeout, for invalid arguments, for invalid wait sets, with a dummy guard and a dummy timer in different wait sets to make sure things are being collated and then updated back properly, and so on. Not to repeat rcl_wait() tests, just to verify the new functionality is correct.
There was a problem hiding this comment.
Yes, I meant to, but forgot.
| size_t number_of_timers = 0u; | ||
| size_t number_of_clients = 0u; | ||
| size_t number_of_services = 0u; | ||
| for (i = 0u; i < num_wait_sets; ++i) { |
There was a problem hiding this comment.
@jacobperron it could be that no wait set was provided, should we have a different rcl error message for that case (right now it'll say that wait sets are empty)?
There was a problem hiding this comment.
My intention was to return RCL_RET_WAIT_SET_EMPTY thinking it is intuitive, but I can add a new return code e.g. RCL_RET_WAIT_SET_NONE.
There was a problem hiding this comment.
Either that or RCL_RET_INVALID_ARGUMENT plus RCL_SET_ERROR_MSG() with a nice message.
| number_of_clients == 0u && | ||
| number_of_services == 0u) | ||
| { | ||
| RCL_SET_ERROR_MSG("wait set is empty"); |
There was a problem hiding this comment.
@jacobperron consider "wait sets are empty" instead.
| { | ||
| RCL_CHECK_ARGUMENT_FOR_NULL(wait_sets, RCL_RET_INVALID_ARGUMENT); | ||
| size_t i; | ||
| size_t j; |
There was a problem hiding this comment.
@jacobperron nit: I have a slight preference for declaring loop variables within the for statement. Won't block if you prefer to keep things C89-ish.
There was a problem hiding this comment.
I guess my head was in C89 mode. Since we're targeting C99, I'm happy to change it.
There was a problem hiding this comment.
| rcl_guard_condition_t * guard_condition = rcl_timer_get_guard_condition(wait_set->timers[j]); | ||
| if (NULL != guard_condition) { | ||
| // rcl_wait() will take care of moving these backwards and setting guard_condition_count. | ||
| const size_t index = wait_set->size_of_guard_conditions + (wait_set->impl->timer_index - 1); |
There was a problem hiding this comment.
@jacobperron not sure I follow how index would take different values across multiple iterations for the same wait_set.
There was a problem hiding this comment.
It won't, this is a copy-paste bug.
| size_t collated_service_index = 0u; | ||
| for (i = 0u; i < num_wait_sets; ++i) { | ||
| wait_set = &wait_sets[i]; | ||
| for (j = 0u; j < wait_set->size_of_timers; ++j) { |
There was a problem hiding this comment.
@jacobperron nit: fine to use for loops, but we could use memcpy too (that depending on the compiler and target architecture may be more performant).
There was a problem hiding this comment.
Sure, I can do that. Do you think there are any issues with readability (and correctness)?
memcpy(
wait_set->timers,
collated_wait_set.timers + collated_timer_index,
sizeof(rcl_timer_t *) * wait_set->size_of_timers);There was a problem hiding this comment.
Ugh, that doesn't look nearly as clean as your current code. Nevermind, let's trust loop unrolling will work :).
|
@hidmic Thanks for the review! I think I've address all of your comments. Ready for another round of review. |
| if (0u == num_wait_sets) { | ||
| RCL_SET_ERROR_MSG("number of wait sets must be greater than zero"); | ||
| return RCL_RET_INVALID_ARGUMENT; | ||
| } |
There was a problem hiding this comment.
Could take a short cut and return rcl_wait() if 1u == num_wait_sets
| ret = rcl_wait_set_init(&wait_sets[i], 0, 1, 1, 0, 0, rcl_get_default_allocator()); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
|
|
||
| // Add a dummy guard condition to avoid an error |
There was a problem hiding this comment.
What error is the dummy guard condition avoiding?
There was a problem hiding this comment.
That is a good question. I copied this over from the existing test involving a timer, without it the test segfaults 😨
I dug into it a bit more, and it seems like the rmw guard condition count isn't being incremented in rcl_wait_set_add_timer(). Adding a dummy guard condition appears to be a hack to get the count to increment...
I think it can be fixed easily by ensuring the rmw guard condition count is incremented when adding timers, but without understanding the reason for the current implementation I am hesitant to change it. @wjwwood, is this a bug or intentional?
There was a problem hiding this comment.
I don't know where it was copied from, but here maybe the error could be avoided if you also update the values passed to rcl_wait_set_init() above?
There was a problem hiding this comment.
4bde955 to
e40a26b
Compare
|
@jacobperron are we pushing this one as-is or are you considering a re-implementation in terms of the feature introduced by #335 ? |
|
Makes total sense to me, let's close it. |
Internally, the function collates all wait sets into a single wait set that is waited on.
Resolves #308