mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 09:37:03 +02:00
This won't help too much because serialization is extremely alloc-heavy and it causes tons of GC pressure, so GC will drastically reduce the effectiveness of parallelization. Still helps a bit though.
21 lines
536 B
C#
21 lines
536 B
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace Robust.Shared.Utility
|
|
{
|
|
internal static class InterlockedHelper
|
|
{
|
|
// Based on https://devblogs.microsoft.com/oldnewthing/20040915-00/?p=37863
|
|
public static void Min(ref uint a, uint b)
|
|
{
|
|
uint original;
|
|
uint result;
|
|
do
|
|
{
|
|
original = a;
|
|
result = Math.Min(original, b);
|
|
} while (Interlocked.CompareExchange(ref a, result, original) != original);
|
|
}
|
|
}
|
|
}
|