diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index 464148582..445a9699d 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -207,7 +207,6 @@ struct CddsWaitset size_t nelems; std::mutex lock; - bool inuse; std::vector subs; std::vector gcs; std::vector cls; @@ -2078,7 +2077,6 @@ extern "C" rmw_wait_set_t * rmw_create_wait_set(rmw_context_t * context, size_t RMW_SET_ERROR_MSG("failed to construct wait set info struct"); goto fail_ws; } - ws->inuse = false; ws->nelems = 0; #if MULTIDOMAIN owner = DDS_CYCLONEDDS_HANDLE; @@ -2221,10 +2219,10 @@ static void clean_waitset_caches() have been cached in a waitset), and drops all cached entities from all waitsets (just to keep life simple). I'm assuming one is not allowed to delete an entity while it is still being used ... */ - std::lock_guard lock(gcdds.lock); + std::lock_guard lock{gcdds.lock}; for (auto && ws : gcdds.waitsets) { - std::lock_guard lock(ws->lock); - if (!ws->inuse) { + std::unique_lock lock2{ws->lock, std::try_to_lock}; + if (lock2.owns_lock()) { waitset_detach(ws); } } @@ -2294,14 +2292,7 @@ extern "C" rmw_ret_t rmw_wait( CddsWaitset * ws = static_cast(wait_set->data); RET_NULL(ws); - { - std::lock_guard lock(ws->lock); - if (ws->inuse) { - RMW_SET_ERROR_MSG("concurrent calls to rmw_wait on a single waitset is not supported"); - return RMW_RET_ERROR; - } - ws->inuse = true; - } + std::lock_guard lock(ws->lock); if (require_reattach( ws->subs, subs ? subs->subscriber_count : 0, @@ -2405,11 +2396,6 @@ extern "C" rmw_ret_t rmw_wait( } #endif - { - std::lock_guard lock(ws->lock); - ws->inuse = false; - } - return (ws->trigs.size() == 1) ? RMW_RET_TIMEOUT : RMW_RET_OK; }