From 6f1113f38be1cbb388311a2bcd0bc658edf29c8e Mon Sep 17 00:00:00 2001 From: Jackie Kay Date: Fri, 1 Apr 2016 14:07:29 -0700 Subject: [PATCH] Remove fixed guard conditions * remove fixed guard conditions * Detach conditions --- rmw_connext_cpp/src/functions.cpp | 4 +- rmw_connext_dynamic_cpp/src/functions.cpp | 4 +- .../shared_functions.hpp | 37 +++++++------- .../src/shared_functions.cpp | 48 +------------------ 4 files changed, 22 insertions(+), 71 deletions(-) diff --git a/rmw_connext_cpp/src/functions.cpp b/rmw_connext_cpp/src/functions.cpp index 274e0339..9d3c8aa2 100644 --- a/rmw_connext_cpp/src/functions.cpp +++ b/rmw_connext_cpp/src/functions.cpp @@ -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 diff --git a/rmw_connext_dynamic_cpp/src/functions.cpp b/rmw_connext_dynamic_cpp/src/functions.cpp index d79b89a3..d527f436 100644 --- a/rmw_connext_dynamic_cpp/src/functions.cpp +++ b/rmw_connext_dynamic_cpp/src/functions.cpp @@ -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 diff --git a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/shared_functions.hpp b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/shared_functions.hpp index 76c67646..4ce1c6a5 100644 --- a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/shared_functions.hpp +++ b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/shared_functions.hpp @@ -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 @@ -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( - 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"); @@ -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 @@ -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"); + } } } @@ -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 @@ -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) { diff --git a/rmw_connext_shared_cpp/src/shared_functions.cpp b/rmw_connext_shared_cpp/src/shared_functions.cpp index 63315a4c..70ebc1c8 100644 --- a/rmw_connext_shared_cpp/src/shared_functions.cpp +++ b/rmw_connext_shared_cpp/src/shared_functions.cpp @@ -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) { @@ -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(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: @@ -645,28 +621,6 @@ destroy_waitset(const char * implementation_identifier, auto result = RMW_RET_OK; ConnextWaitSetInfo * waitset_info = static_cast(waitset->data); - DDS::WaitSet * dds_waitset = - static_cast(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( - fixed_guard_conditions->guard_conditions[i]); - if (!guard_cond) { - continue; - } - DDS::GuardCondition * dds_guard_cond = static_cast(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) {