Skip to content

Commit

Permalink
[Collision.Response.Contact] Make contactId thread-safe (#4582)
Browse files Browse the repository at this point in the history
* local storage for available ids

* remove availableId and make the counter atomic

* fix compilation for linux

---------

Co-authored-by: erik pernod <[email protected]>
  • Loading branch information
fredroy and epernod authored Apr 1, 2024
1 parent 7d4f1e2 commit 34346a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,7 @@ namespace sofa::component::collision::response::contact

ContactIdentifier::ContactIdentifier()
{
if (!availableId.empty())
{
id = availableId.front();
availableId.pop_front();
}
else
id = cpt++;
}

ContactIdentifier::~ContactIdentifier()
{
availableId.push_back(id);
id = cpt.fetch_add(1) ;
}

} //namespace sofa::component::collision::response::contact
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <sofa/core/collision/DetectionOutput.h>
#include <list>
#include <atomic>


namespace sofa::component::collision::response::contact
Expand All @@ -33,12 +34,11 @@ class SOFA_COMPONENT_COLLISION_RESPONSE_CONTACT_API ContactIdentifier
{
public:
ContactIdentifier();
virtual ~ContactIdentifier();
virtual ~ContactIdentifier() = default;

protected:
inline static sofa::core::collision::DetectionOutput::ContactId cpt = 0;
inline static std::atomic<sofa::core::collision::DetectionOutput::ContactId> cpt = 0;
sofa::core::collision::DetectionOutput::ContactId id;
inline static std::list<sofa::core::collision::DetectionOutput::ContactId> availableId;
};

inline long cantorPolynomia(sofa::core::collision::DetectionOutput::ContactId x, sofa::core::collision::DetectionOutput::ContactId y)
Expand Down

0 comments on commit 34346a2

Please sign in to comment.