Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Remove fixed guard conditions
Browse files Browse the repository at this point in the history
* remove fixed guard conditions

* Detach conditions
  • Loading branch information
jacquelinekay committed Apr 1, 2016
1 parent c9d750a commit 6f1113f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 71 deletions.
4 changes: 2 additions & 2 deletions rmw_connext_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ rmw_trigger_guard_condition(const rmw_guard_condition_t * guard_condition_handle
}

rmw_waitset_t *
rmw_create_waitset(rmw_guard_conditions_t * fixed_guard_conditions, size_t max_conditions)
rmw_create_waitset(size_t max_conditions)
{
return create_waitset(rti_connext_identifier, fixed_guard_conditions, max_conditions);
return create_waitset(rti_connext_identifier, max_conditions);
}

rmw_ret_t
Expand Down
4 changes: 2 additions & 2 deletions rmw_connext_dynamic_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,9 +2235,9 @@ rmw_trigger_guard_condition(const rmw_guard_condition_t * guard_condition_handle
}

rmw_waitset_t *
rmw_create_waitset(rmw_guard_conditions_t * fixed_guard_conditions, size_t max_conditions)
rmw_create_waitset(size_t max_conditions)
{
return create_waitset(rti_connext_dynamic_identifier, fixed_guard_conditions, max_conditions);
return create_waitset(rti_connext_dynamic_identifier, max_conditions);
}

rmw_ret_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ destroy_guard_condition(const char * implementation_identifier,

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_waitset_t *
create_waitset(const char * implementation_identifier,
rmw_guard_conditions_t * fixed_guard_conditions, size_t max_conditions);
create_waitset(const char * implementation_identifier, size_t max_conditions);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
Expand Down Expand Up @@ -219,24 +218,6 @@ wait(const char * implementation_identifier,
}

for (DDS_Long i = 0; i < attached_conditions->length(); ++i) {
bool fixed = false;
for (uint32_t j = 0; j < waitset->fixed_guard_conditions->guard_condition_count; ++j) {
DDS::GuardCondition * fixed_guard_cond = static_cast<DDSGuardCondition *>(
waitset->fixed_guard_conditions->guard_conditions[j]);
if (fixed_guard_cond == (*attached_conditions)[i]) {
// Reset the fixed guard conditions to avoid being woken up
// immediately next time.
retcode = fixed_guard_cond->set_trigger_value(DDS_BOOLEAN_FALSE);
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "failed to set trigger value\n");
}
fixed = true;
break;
}
}
if (fixed) {
continue;
}
retcode = dds_waitset->detach_condition((*attached_conditions)[i]);
if (retcode != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
Expand Down Expand Up @@ -402,6 +383,10 @@ wait(const char * implementation_identifier,
if (!(j < active_conditions->length())) {
subscriptions->subscribers[i] = 0;
}
DDS_ReturnCode_t retcode = dds_waitset->detach_condition(read_condition);
if (retcode != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
}
}

// set guard condition handles to zero for all not triggered conditions
Expand Down Expand Up @@ -432,6 +417,10 @@ wait(const char * implementation_identifier,
if (!(j < active_conditions->length())) {
guard_conditions->guard_conditions[i] = 0;
}
DDS_ReturnCode_t retcode = dds_waitset->detach_condition(condition);
if (retcode != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
}
}
}

Expand Down Expand Up @@ -461,6 +450,10 @@ wait(const char * implementation_identifier,
if (!(j < active_conditions->length())) {
services->services[i] = 0;
}
DDS_ReturnCode_t retcode = dds_waitset->detach_condition(read_condition);
if (retcode != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
}
}

// set client handles to zero for all not triggered conditions
Expand Down Expand Up @@ -489,6 +482,10 @@ wait(const char * implementation_identifier,
if (!(j < active_conditions->length())) {
clients->clients[i] = 0;
}
DDS_ReturnCode_t retcode = dds_waitset->detach_condition(read_condition);
if (retcode != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
}
}

if (status == DDS_RETCODE_TIMEOUT) {
Expand Down
48 changes: 1 addition & 47 deletions rmw_connext_shared_cpp/src/shared_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,11 @@ destroy_guard_condition(const char * implementation_identifier,
}

rmw_waitset_t *
create_waitset(const char * implementation_identifier,
rmw_guard_conditions_t * fixed_guard_conditions, size_t max_conditions)
create_waitset(const char * implementation_identifier, size_t max_conditions)
{
rmw_waitset_t * waitset = rmw_waitset_allocate();

ConnextWaitSetInfo * waitset_info = nullptr;
DDSGuardCondition * dds_guard_cond = nullptr;
DDS_ReturnCode_t ret;

// From here onward, error results in unrolling in the goto fail block.
if (!waitset) {
Expand Down Expand Up @@ -579,27 +576,6 @@ create_waitset(const char * implementation_identifier,
DDSConditionSeq)
}

waitset->fixed_guard_conditions = fixed_guard_conditions;
if (fixed_guard_conditions && fixed_guard_conditions->guard_condition_count > 0) {
if (!fixed_guard_conditions->guard_conditions) {
RMW_SET_ERROR_MSG("Received invalid guard condition array");
goto fail;
}
// We also need to attach the fixed guard conditions to the waitset (and detach them in destroy)
for (size_t i = 0; i < fixed_guard_conditions->guard_condition_count; ++i) {
void * guard_cond = fixed_guard_conditions->guard_conditions[i];
if (!guard_cond) {
RMW_SET_ERROR_MSG("Received invalid guard condition");
goto fail;
}
dds_guard_cond = static_cast<DDSGuardCondition *>(guard_cond);
ret = waitset_info->waitset->attach_condition(dds_guard_cond);
if (ret != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to attach condition to waitset");
}
}
}

return waitset;

fail:
Expand Down Expand Up @@ -645,28 +621,6 @@ destroy_waitset(const char * implementation_identifier,

auto result = RMW_RET_OK;
ConnextWaitSetInfo * waitset_info = static_cast<ConnextWaitSetInfo *>(waitset->data);
DDS::WaitSet * dds_waitset =
static_cast<DDSWaitSet *>(waitset_info->waitset);

const rmw_guard_conditions_t * fixed_guard_conditions = waitset->fixed_guard_conditions;
if (fixed_guard_conditions && fixed_guard_conditions->guard_conditions && dds_waitset) {
// We also need to attach the fixed guard conditions to the waitset (and detach them in destroy)
for (size_t i = 0; i < fixed_guard_conditions->guard_condition_count; ++i) {
void * guard_cond = static_cast<rmw_guard_condition_t *>(
fixed_guard_conditions->guard_conditions[i]);
if (!guard_cond) {
continue;
}
DDS::GuardCondition * dds_guard_cond = static_cast<DDSGuardCondition *>(guard_cond);
if (!dds_guard_cond) {
continue;
}
DDS_ReturnCode_t ret = dds_waitset->detach_condition(dds_guard_cond);
if (ret != DDS_RETCODE_OK) {
RMW_SET_ERROR_MSG("Failed to detach condition from waitset");
}
}
}

// Explicitly call destructor since the "placement new" was used
if (waitset_info->active_conditions) {
Expand Down

0 comments on commit 6f1113f

Please sign in to comment.