diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs index 16bb9bbf4e256f..6c6f0d6576b93b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs @@ -132,7 +132,7 @@ public static ulong Read(ref ulong location) => /// Bitwise "ands" two 32-bit signed integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int And(ref int location1, int value) @@ -144,7 +144,7 @@ public static int And(ref int location1, int value) int oldValue = CompareExchange(ref location1, newValue, current); if (oldValue == current) { - return newValue; + return oldValue; } current = oldValue; } @@ -153,7 +153,7 @@ public static int And(ref int location1, int value) /// Bitwise "ands" two 32-bit unsigned integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] @@ -163,7 +163,7 @@ public static uint And(ref uint location1, uint value) => /// Bitwise "ands" two 64-bit signed integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long And(ref long location1, long value) @@ -175,7 +175,7 @@ public static long And(ref long location1, long value) long oldValue = CompareExchange(ref location1, newValue, current); if (oldValue == current) { - return newValue; + return oldValue; } current = oldValue; } @@ -184,7 +184,7 @@ public static long And(ref long location1, long value) /// Bitwise "ands" two 64-bit unsigned integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] @@ -196,7 +196,7 @@ public static ulong And(ref ulong location1, ulong value) => /// Bitwise "ors" two 32-bit signed integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Or(ref int location1, int value) @@ -208,7 +208,7 @@ public static int Or(ref int location1, int value) int oldValue = CompareExchange(ref location1, newValue, current); if (oldValue == current) { - return newValue; + return oldValue; } current = oldValue; } @@ -217,7 +217,7 @@ public static int Or(ref int location1, int value) /// Bitwise "ors" two 32-bit unsigned integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] @@ -227,7 +227,7 @@ public static uint Or(ref uint location1, uint value) => /// Bitwise "ors" two 64-bit signed integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Or(ref long location1, long value) @@ -239,7 +239,7 @@ public static long Or(ref long location1, long value) long oldValue = CompareExchange(ref location1, newValue, current); if (oldValue == current) { - return newValue; + return oldValue; } current = oldValue; } @@ -248,7 +248,7 @@ public static long Or(ref long location1, long value) /// Bitwise "ors" two 64-bit unsigned integers and replaces the first integer with the result, as an atomic operation. /// A variable containing the first value to be combined. The result is stored in . /// The value to be combined with the integer at . - /// The new value stored at . + /// The original value in . /// The address of is a null pointer. [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] diff --git a/src/libraries/System.Threading/tests/InterlockedTests.cs b/src/libraries/System.Threading/tests/InterlockedTests.cs index 6febd84ef5dbfb..5d7b053b838384 100644 --- a/src/libraries/System.Threading/tests/InterlockedTests.cs +++ b/src/libraries/System.Threading/tests/InterlockedTests.cs @@ -242,7 +242,7 @@ public void InterlockedRead_UInt64() public void InterlockedAnd_Int32() { int value = 0x12345670; - Assert.Equal(0x02244220, Interlocked.And(ref value, 0x7654321)); + Assert.Equal(0x12345670, Interlocked.And(ref value, 0x7654321)); Assert.Equal(0x02244220, value); } @@ -250,7 +250,7 @@ public void InterlockedAnd_Int32() public void InterlockedAnd_UInt32() { uint value = 0x12345670u; - Assert.Equal(0x02244220u, Interlocked.And(ref value, 0x7654321)); + Assert.Equal(0x12345670u, Interlocked.And(ref value, 0x7654321)); Assert.Equal(0x02244220u, value); } @@ -258,7 +258,7 @@ public void InterlockedAnd_UInt32() public void InterlockedAnd_Int64() { long value = 0x12345670; - Assert.Equal(0x02244220, Interlocked.And(ref value, 0x7654321)); + Assert.Equal(0x12345670, Interlocked.And(ref value, 0x7654321)); Assert.Equal(0x02244220, value); } @@ -266,7 +266,7 @@ public void InterlockedAnd_Int64() public void InterlockedAnd_UInt64() { ulong value = 0x12345670u; - Assert.Equal(0x02244220u, Interlocked.And(ref value, 0x7654321)); + Assert.Equal(0x12345670u, Interlocked.And(ref value, 0x7654321)); Assert.Equal(0x02244220u, value); } @@ -274,7 +274,7 @@ public void InterlockedAnd_UInt64() public void InterlockedOr_Int32() { int value = 0x12345670; - Assert.Equal(0x17755771, Interlocked.Or(ref value, 0x7654321)); + Assert.Equal(0x12345670, Interlocked.Or(ref value, 0x7654321)); Assert.Equal(0x17755771, value); } @@ -282,7 +282,7 @@ public void InterlockedOr_Int32() public void InterlockedOr_UInt32() { uint value = 0x12345670u; - Assert.Equal(0x17755771u, Interlocked.Or(ref value, 0x7654321)); + Assert.Equal(0x12345670u, Interlocked.Or(ref value, 0x7654321)); Assert.Equal(0x17755771u, value); } @@ -290,7 +290,7 @@ public void InterlockedOr_UInt32() public void InterlockedOr_Int64() { long value = 0x12345670; - Assert.Equal(0x17755771, Interlocked.Or(ref value, 0x7654321)); + Assert.Equal(0x12345670, Interlocked.Or(ref value, 0x7654321)); Assert.Equal(0x17755771, value); } @@ -298,7 +298,7 @@ public void InterlockedOr_Int64() public void InterlockedOr_UInt64() { ulong value = 0x12345670u; - Assert.Equal(0x17755771u, Interlocked.Or(ref value, 0x7654321)); + Assert.Equal(0x12345670u, Interlocked.Or(ref value, 0x7654321)); Assert.Equal(0x17755771u, value); }