Files
mirror-processhacker/1.x/trunk/ProcessHacker.Common/Threading/Interlocked2.cs
T
wj32 76972653c2 added some more stats to Fair and FastResourceLock
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2499 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2009-12-25 05:47:28 +00:00

31 lines
738 B
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ProcessHacker.Common.Threading
{
public static class Interlocked2
{
public static int Set(ref int location, Predicate<int> predicate, Func<int, int> transform)
{
int value;
while (true)
{
value = location;
if (!predicate(value))
return value;
if (Interlocked.CompareExchange(
ref location,
transform(value),
value
) == value)
return value;
}
}
}
}