Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
replace volatile locks with Interlocked methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast committed May 6, 2018
1 parent a842fb9 commit 830cdbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions Physics2D/Dynamics/Contacts/ContactSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private void SolveVelocityConstraints(int start, int end)
{
if (Interlocked.CompareExchange(ref _velocities[orderedIndexB].Lock, 1, 0) == 0)
break;
_velocities[orderedIndexA].Lock = 0;
System.Threading.Interlocked.Exchange(ref _velocities[orderedIndexA].Lock, 0);
}
#if NET40 || NET45
Thread.Sleep(0);
Expand Down Expand Up @@ -770,8 +770,8 @@ private void SolveVelocityConstraints(int start, int end)
_velocities[indexB].w = wB;

#if NET40 || NET45 || PORTABLE40 || PORTABLE45 || W10 || W8_1 || WP8_1
_velocities[orderedIndexB].Lock = 0;
_velocities[orderedIndexA].Lock = 0;
System.Threading.Interlocked.Exchange(ref _velocities[orderedIndexB].Lock, 0);
System.Threading.Interlocked.Exchange(ref _velocities[orderedIndexA].Lock, 0);
#endif
}
}
Expand Down Expand Up @@ -853,7 +853,7 @@ private bool SolvePositionConstraints(int start, int end)
{
if (Interlocked.CompareExchange(ref _positions[orderedIndexB].Lock, 1, 0) == 0)
break;
_positions[orderedIndexA].Lock = 0;
System.Threading.Interlocked.Exchange(ref _positions[orderedIndexA].Lock, 0);
}
#if NET40 || NET45
Thread.Sleep(0);
Expand Down Expand Up @@ -924,8 +924,8 @@ private bool SolvePositionConstraints(int start, int end)

#if NET40 || NET45 || PORTABLE40 || PORTABLE45 || W10 || W8_1 || WP8_1
// Unlock bodies.
_positions[orderedIndexB].Lock = 0;
_positions[orderedIndexA].Lock = 0;
System.Threading.Interlocked.Exchange(ref _positions[orderedIndexB].Lock, 0);
System.Threading.Interlocked.Exchange(ref _positions[orderedIndexA].Lock, 0);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions Physics2D/Dynamics/TimeStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public struct Position
{
public Vector2 c;
public float a;
internal volatile int Lock;
internal int Lock;
}

/// This is an internal structure.
public struct Velocity
{
public Vector2 v;
public float w;
internal volatile int Lock;
internal int Lock;
}

/// Solver Data
Expand Down

0 comments on commit 830cdbd

Please sign in to comment.