Skip to content

Commit 56b2a2a

Browse files
authored
Use nint for native-sized integers in Volatile (#118360)
1 parent a483fd3 commit 56b2a2a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ public void SetCompressedStack(CompressedStack stack)
586586
public static long VolatileRead(ref long address) => Volatile.Read(ref address);
587587
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
588588
[EditorBrowsable(EditorBrowsableState.Never)]
589-
public static IntPtr VolatileRead(ref IntPtr address) => Volatile.Read(ref address);
589+
public static nint VolatileRead(ref nint address) => Volatile.Read(ref address);
590590
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
591591
[EditorBrowsable(EditorBrowsableState.Never)]
592592
[return: NotNullIfNotNull(nameof(address))]
@@ -613,7 +613,7 @@ public void SetCompressedStack(CompressedStack stack)
613613
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
614614
[EditorBrowsable(EditorBrowsableState.Never)]
615615
[CLSCompliant(false)]
616-
public static UIntPtr VolatileRead(ref UIntPtr address) => Volatile.Read(ref address);
616+
public static nuint VolatileRead(ref nuint address) => Volatile.Read(ref address);
617617
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
618618
[EditorBrowsable(EditorBrowsableState.Never)]
619619
public static void VolatileWrite(ref byte address, byte value) => Volatile.Write(ref address, value);
@@ -631,7 +631,7 @@ public void SetCompressedStack(CompressedStack stack)
631631
public static void VolatileWrite(ref long address, long value) => Volatile.Write(ref address, value);
632632
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
633633
[EditorBrowsable(EditorBrowsableState.Never)]
634-
public static void VolatileWrite(ref IntPtr address, IntPtr value) => Volatile.Write(ref address, value);
634+
public static void VolatileWrite(ref nint address, nint value) => Volatile.Write(ref address, value);
635635
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
636636
[EditorBrowsable(EditorBrowsableState.Never)]
637637
public static void VolatileWrite([NotNullIfNotNull(nameof(value))] ref object? address, object? value) => Volatile.Write(ref address, value);
@@ -657,7 +657,7 @@ public void SetCompressedStack(CompressedStack stack)
657657
[Obsolete(Obsoletions.ThreadVolatileReadWriteMessage, DiagnosticId = Obsoletions.ThreadVolatileReadWriteDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
658658
[EditorBrowsable(EditorBrowsableState.Never)]
659659
[CLSCompliant(false)]
660-
public static void VolatileWrite(ref UIntPtr address, UIntPtr value) => Volatile.Write(ref address, value);
660+
public static void VolatileWrite(ref nuint address, nuint value) => Volatile.Write(ref address, value);
661661

662662
/// <summary>
663663
/// Manages functionality required to support members of <see cref="Thread"/> dealing with thread-local data

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ public static void Write(ref long location, long value) =>
107107
#endregion
108108

109109
#region IntPtr
110-
private struct VolatileIntPtr { public volatile IntPtr Value; }
110+
private struct VolatileIntPtr { public volatile nint Value; }
111111

112112
[Intrinsic]
113113
[NonVersionable]
114-
public static IntPtr Read(ref readonly IntPtr location) =>
115-
Unsafe.As<IntPtr, VolatileIntPtr>(ref Unsafe.AsRef(in location)).Value;
114+
public static nint Read(ref readonly nint location) =>
115+
Unsafe.As<nint, VolatileIntPtr>(ref Unsafe.AsRef(in location)).Value;
116116

117117
[Intrinsic]
118118
[NonVersionable]
119-
public static void Write(ref IntPtr location, IntPtr value) =>
120-
Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value = value;
119+
public static void Write(ref nint location, nint value) =>
120+
Unsafe.As<nint, VolatileIntPtr>(ref location).Value = value;
121121
#endregion
122122

123123
#region SByte
@@ -197,19 +197,19 @@ public static void Write(ref ulong location, ulong value) =>
197197
#endregion
198198

199199
#region UIntPtr
200-
private struct VolatileUIntPtr { public volatile UIntPtr Value; }
200+
private struct VolatileUIntPtr { public volatile nuint Value; }
201201

202202
[CLSCompliant(false)]
203203
[Intrinsic]
204204
[NonVersionable]
205-
public static UIntPtr Read(ref readonly UIntPtr location) =>
206-
Unsafe.As<UIntPtr, VolatileUIntPtr>(ref Unsafe.AsRef(in location)).Value;
205+
public static nuint Read(ref readonly nuint location) =>
206+
Unsafe.As<nuint, VolatileUIntPtr>(ref Unsafe.AsRef(in location)).Value;
207207

208208
[CLSCompliant(false)]
209209
[Intrinsic]
210210
[NonVersionable]
211-
public static void Write(ref UIntPtr location, UIntPtr value) =>
212-
Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value = value;
211+
public static void Write(ref nuint location, nuint value) =>
212+
Unsafe.As<nuint, VolatileUIntPtr>(ref location).Value = value;
213213
#endregion
214214

215215
#region T

0 commit comments

Comments
 (0)