Skip to content

Commit 9236418

Browse files
giritrivediroot
authored andcommitted
Fix big endian issue in Interlocked test cases (dotnet#101429)
Fix big indian issue wiht BitConverted as part of intercloked test cases. These were causing failures in runtime_community pipeline --------- Co-authored-by: root <root@t8375036.lnxero1.boe>
1 parent bec07d1 commit 9236418

File tree

1 file changed

+2
-2
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Threading

1 file changed

+2
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static unsafe ushort Exchange(ref ushort location1, ushort value)
126126
nuint offset = Unsafe.OpportunisticMisalignment(ref location1, sizeof(uint));
127127
ref uint alignedRef = ref Unsafe.As<ushort, uint>(ref Unsafe.SubtractByteOffset(ref location1, offset));
128128
int bitOffset =
129-
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(byte)) * 8); // to bit offset
129+
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(ushort)) * 8); // to bit offset
130130
Debug.Assert(bitOffset is 0 or 16);
131131
uint mask = ~((uint)ushort.MaxValue << bitOffset);
132132
uint shiftedValue = (uint)value << bitOffset;
@@ -308,7 +308,7 @@ public static unsafe ushort CompareExchange(ref ushort location1, ushort value,
308308
nuint offset = Unsafe.OpportunisticMisalignment(ref location1, sizeof(uint));
309309
ref uint alignedRef = ref Unsafe.As<ushort, uint>(ref Unsafe.SubtractByteOffset(ref location1, offset));
310310
int bitOffset =
311-
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(byte)) * 8); // to bit offset
311+
(int)((BitConverter.IsLittleEndian ? offset : sizeof(uint) - offset - sizeof(ushort)) * 8); // to bit offset
312312
Debug.Assert(bitOffset is 0 or 16);
313313
uint mask = ~((uint)ushort.MaxValue << bitOffset);
314314
uint shiftedValue = (uint)value << bitOffset;

0 commit comments

Comments
 (0)