Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove suspicious wait set locking code #119

Open
wants to merge 3 commits into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ struct CddsWaitset
size_t nelems;

std::mutex lock;
bool inuse;
std::vector<CddsSubscription *> subs;
std::vector<CddsGuardCondition *> gcs;
std::vector<CddsClient *> cls;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::mutex> lock(gcdds.lock);
std::lock_guard<std::mutex> lock{gcdds.lock};
for (auto && ws : gcdds.waitsets) {
std::lock_guard<std::mutex> lock(ws->lock);
if (!ws->inuse) {
std::unique_lock<std::mutex> lock2{ws->lock, std::try_to_lock};
if (lock2.owns_lock()) {
waitset_detach(ws);
}
}
Expand Down Expand Up @@ -2294,14 +2292,7 @@ extern "C" rmw_ret_t rmw_wait(
CddsWaitset * ws = static_cast<CddsWaitset *>(wait_set->data);
RET_NULL(ws);

{
std::lock_guard<std::mutex> 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<std::mutex> lock(ws->lock);

if (require_reattach(
ws->subs, subs ? subs->subscriber_count : 0,
Expand Down Expand Up @@ -2405,11 +2396,6 @@ extern "C" rmw_ret_t rmw_wait(
}
#endif

{
std::lock_guard<std::mutex> lock(ws->lock);
ws->inuse = false;
}

return (ws->trigs.size() == 1) ? RMW_RET_TIMEOUT : RMW_RET_OK;
}

Expand Down