Skip to content

Commit

Permalink
Merge pull request #1310 from rabbitmq/rabbitmq-dotnet-client-1308-2
Browse files Browse the repository at this point in the history
Part 2 of #1308 - Port Interlocked.cs from #982
  • Loading branch information
lukebakken authored Mar 14, 2023
2 parents 1a2a9be + 055e06e commit d457b01
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions projects/RabbitMQ.Client/FrameworkExtension/Interlocked.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Note:
// The code in this file is inspired by the code in `dotnet/runtime`, in this file:
// src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs
//
// The license from that file is as follows:
//
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace RabbitMQ.Client
{
#if NETSTANDARD
// TODO GH-1308 class should be called "Interlocked" to be used by other code
internal static class InterlockedExtensions
{
public static ulong CompareExchange(ref ulong location1, ulong value, ulong comparand)
{
return (ulong)System.Threading.Interlocked.CompareExchange(ref Unsafe.As<ulong, long>(ref location1), (long)value, (long)comparand);
}

public static ulong Increment(ref ulong location1)
{
return (ulong)System.Threading.Interlocked.Add(ref Unsafe.As<ulong, long>(ref location1), 1L);
}
}
#endif
}

0 comments on commit d457b01

Please sign in to comment.