Skip to content

Commit

Permalink
Merge pull request #123 from computablee/performance
Browse files Browse the repository at this point in the history
Optimize #118
  • Loading branch information
computablee authored Nov 25, 2023
2 parents 33a8e90 + 708a1ff commit aa833ba
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions DotMP/Atomic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public static uint Add(ref uint target, uint value)
/// <returns>The new value stored as a result of the operation.</returns>
public static uint Sub(ref uint target, uint value)
{
int neg = -(int)value;
return Interlocked.Add(ref target, Unsafe.As<int, uint>(ref neg));
uint neg = ~value + 1;
return Interlocked.Add(ref target, neg);
}

/// <summary>
Expand Down Expand Up @@ -246,8 +246,8 @@ public static ulong Add(ref ulong target, ulong value)
/// <returns>The new value stored as a result of the operation.</returns>
public static ulong Sub(ref ulong target, ulong value)
{
long neg = -(long)value;
return Interlocked.Add(ref target, Unsafe.As<long, ulong>(ref neg));
ulong neg = ~value + 1;
return Interlocked.Add(ref target, neg);
}

/// <summary>
Expand Down

0 comments on commit aa833ba

Please sign in to comment.