Skip to content

Commit d457b01

Browse files
authored
Merge pull request #1310 from rabbitmq/rabbitmq-dotnet-client-1308-2
Part 2 of #1308 - Port Interlocked.cs from #982
2 parents 1a2a9be + 055e06e commit d457b01

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Note:
2+
// The code in this file is inspired by the code in `dotnet/runtime`, in this file:
3+
// src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs
4+
//
5+
// The license from that file is as follows:
6+
//
7+
// Licensed to the .NET Foundation under one or more agreements.
8+
// The .NET Foundation licenses this file to you under the MIT license.
9+
10+
using System.Runtime.CompilerServices;
11+
12+
namespace RabbitMQ.Client
13+
{
14+
#if NETSTANDARD
15+
// TODO GH-1308 class should be called "Interlocked" to be used by other code
16+
internal static class InterlockedExtensions
17+
{
18+
public static ulong CompareExchange(ref ulong location1, ulong value, ulong comparand)
19+
{
20+
return (ulong)System.Threading.Interlocked.CompareExchange(ref Unsafe.As<ulong, long>(ref location1), (long)value, (long)comparand);
21+
}
22+
23+
public static ulong Increment(ref ulong location1)
24+
{
25+
return (ulong)System.Threading.Interlocked.Add(ref Unsafe.As<ulong, long>(ref location1), 1L);
26+
}
27+
}
28+
#endif
29+
}

0 commit comments

Comments
 (0)