Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ void LongLivedObjectCollection::add(std::shared_ptr<LongLivedObject> so) {

void LongLivedObjectCollection::remove(const LongLivedObject* o) {
std::scoped_lock lock(collectionMutex_);
for (auto p = collection_.begin(); p != collection_.end(); p++) {
if (p->get() == o) {
collection_.erase(p);
break;
}
// Empty owner: lookup-only alias, with no ownership or control block.
const std::shared_ptr<LongLivedObject> lookupKey{
std::shared_ptr<LongLivedObject>{}, const_cast<LongLivedObject*>(o)};

// A shared_ptr hashes and compares by the pointer it stores, so a
// non-owning shared_ptr to `o` finds its entry without walking the set.
auto entry = collection_.find(lookupKey);
if (entry != collection_.end()) {
collection_.erase(entry);
Comment thread
javache marked this conversation as resolved.
Resolved
}
}

Expand Down
Loading