Files
RobustToolbox/Robust.Shared/Utility/InterlockedHelper.cs
Pieter-Jan Briers 7bc847c9a4 Multithread game state serialization, fix some possible thread bugs.
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.
2021-10-04 02:20:13 +02:00

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);
}
}
}