Skip to content

Commit

Permalink
Prevent lock contention for arbiters.
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Dec 23, 2024
1 parent 92058c6 commit 65ace63
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Jitter2/World.Detect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,23 +427,24 @@ public void GetArbiter(ulong id0, ulong id1, RigidBody b0, RigidBody b1, out Arb
arb = new Arbiter();
}

var h = memContacts.Allocate(true);
arb.Handle = h;
h.Data.Init(b0, b1);
h.Data.Key = arbiterKey;
arb.Body1 = b0;
arb.Body2 = b1;

Debug.Assert(arb != null && memContacts.IsActive(arb.Handle));

bool success = arbiters.TryAdd(arbiterKey, arb);

if (success)
{
var h = memContacts.Allocate(true);
arb.Handle = h;
h.Data.Init(b0, b1);
h.Data.Key = arbiterKey;
arb.Body1 = b0;
arb.Body2 = b1;

Debug.Assert(arb != null && memContacts.IsActive(arb.Handle));

deferredArbiters.Add(arb);
}
else
{
memContacts.Free(h);
Arbiter.Pool.Push(arb);
}
}
Expand Down

0 comments on commit 65ace63

Please sign in to comment.