diff --git a/src/coreclr/System.Private.CoreLib/src/System/Threading/Interlocked.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Threading/Interlocked.CoreCLR.cs index 2982dd1777a767..6ee5eb20c8f646 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Threading/Interlocked.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Threading/Interlocked.CoreCLR.cs @@ -60,22 +60,6 @@ public static long Decrement(ref long location) => [MethodImpl(MethodImplOptions.InternalCall)] public static extern long Exchange(ref long location1, long value); - /// Sets a single-precision floating point number to a specified value and returns the original value, as an atomic operation. - /// The variable to set to the specified value. - /// The value to which the parameter is set. - /// The original value of . - /// The address of location1 is a null pointer. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern float Exchange(ref float location1, float value); - - /// Sets a double-precision floating point number to a specified value and returns the original value, as an atomic operation. - /// The variable to set to the specified value. - /// The value to which the parameter is set. - /// The original value of . - /// The address of location1 is a null pointer. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern double Exchange(ref double location1, double value); - /// Sets an object to the specified value and returns a reference to the original object, as an atomic operation. /// The variable to set to the specified value. /// The value to which the parameter is set. @@ -122,24 +106,6 @@ public static T Exchange([NotNullIfNotNull(nameof(value))] ref T location1, T [MethodImpl(MethodImplOptions.InternalCall)] public static extern long CompareExchange(ref long location1, long value, long comparand); - /// Compares two single-precision floating point numbers for equality and, if they are equal, replaces the first value. - /// The destination, whose value is compared with and possibly replaced. - /// The value that replaces the destination value if the comparison results in equality. - /// The value that is compared to the value at . - /// The original value in . - /// The address of is a null pointer. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern float CompareExchange(ref float location1, float value, float comparand); - - /// Compares two double-precision floating point numbers for equality and, if they are equal, replaces the first value. - /// The destination, whose value is compared with and possibly replaced. - /// The value that replaces the destination value if the comparison results in equality. - /// The value that is compared to the value at . - /// The original value in . - /// The address of is a null pointer. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern double CompareExchange(ref double location1, double value, double comparand); - /// Compares two objects for reference equality and, if they are equal, replaces the first object. /// The destination object that is compared by reference with and possibly replaced. /// The object that replaces the destination object if the reference comparison results in equality. diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs index c3ef6daf4382d3..f8a5e61ecbb65c 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs @@ -4,9 +4,6 @@ using System.Runtime; using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; -using System.Runtime.Versioning; - -using Internal.Runtime.CompilerServices; namespace System.Threading { @@ -26,22 +23,6 @@ public static long CompareExchange(ref long location1, long value, long comparan return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); } - [Intrinsic] - public static unsafe float CompareExchange(ref float location1, float value, float comparand) - { - float ret; - *(int*)&ret = CompareExchange(ref Unsafe.As(ref location1), *(int*)&value, *(int*)&comparand); - return ret; - } - - [Intrinsic] - public static unsafe double CompareExchange(ref double location1, double value, double comparand) - { - double ret; - *(long*)&ret = CompareExchange(ref Unsafe.As(ref location1), *(long*)&value, *(long*)&comparand); - return ret; - } - [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: NotNullIfNotNull(nameof(location1))] @@ -87,22 +68,6 @@ public static long Exchange(ref long location1, long value) return oldValue; } - [Intrinsic] - public static unsafe float Exchange(ref float location1, float value) - { - float ret; - *(int*)&ret = Exchange(ref Unsafe.As(ref location1), *(int*)&value); - return ret; - } - - [Intrinsic] - public static unsafe double Exchange(ref double location1, double value) - { - double ret; - *(long*)&ret = Exchange(ref Unsafe.As(ref location1), *(long*)&value); - return ret; - } - [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: NotNullIfNotNull(nameof(location1))] diff --git a/src/coreclr/vm/comutilnative.cpp b/src/coreclr/vm/comutilnative.cpp index 4ece25ea72fdf3..f2985222815e20 100644 --- a/src/coreclr/vm/comutilnative.cpp +++ b/src/coreclr/vm/comutilnative.cpp @@ -1523,59 +1523,6 @@ FCIMPL3_IVV(INT64, COMInterlocked::CompareExchange64, INT64* location, INT64 val } FCIMPLEND -FCIMPL2_IV(float,COMInterlocked::ExchangeFloat, float *location, float value) -{ - FCALL_CONTRACT; - - if( NULL == location) { - FCThrow(kNullReferenceException); - } - - LONG ret = InterlockedExchange((LONG *) location, *(LONG*)&value); - return *(float*)&ret; -} -FCIMPLEND - -FCIMPL2_IV(double,COMInterlocked::ExchangeDouble, double *location, double value) -{ - FCALL_CONTRACT; - - if( NULL == location) { - FCThrow(kNullReferenceException); - } - - - INT64 ret = InterlockedExchange64((INT64 *) location, *(INT64*)&value); - return *(double*)&ret; -} -FCIMPLEND - -FCIMPL3_IVV(float,COMInterlocked::CompareExchangeFloat, float *location, float value, float comparand) -{ - FCALL_CONTRACT; - - if( NULL == location) { - FCThrow(kNullReferenceException); - } - - LONG ret = (LONG)InterlockedCompareExchange((LONG*) location, *(LONG*)&value, *(LONG*)&comparand); - return *(float*)&ret; -} -FCIMPLEND - -FCIMPL3_IVV(double,COMInterlocked::CompareExchangeDouble, double *location, double value, double comparand) -{ - FCALL_CONTRACT; - - if( NULL == location) { - FCThrow(kNullReferenceException); - } - - INT64 ret = (INT64)InterlockedCompareExchange64((INT64*) location, *(INT64*)&value, *(INT64*)&comparand); - return *(double*)&ret; -} -FCIMPLEND - FCIMPL2(LPVOID,COMInterlocked::ExchangeObject, LPVOID*location, LPVOID value) { FCALL_CONTRACT; diff --git a/src/coreclr/vm/comutilnative.h b/src/coreclr/vm/comutilnative.h index fa2ce283791a44..37e19a14f6ec3a 100644 --- a/src/coreclr/vm/comutilnative.h +++ b/src/coreclr/vm/comutilnative.h @@ -227,10 +227,6 @@ class COMInterlocked static FCDECL2_IV(INT64, Exchange64, INT64 *location, INT64 value); static FCDECL3(INT32, CompareExchange, INT32* location, INT32 value, INT32 comparand); static FCDECL3_IVV(INT64, CompareExchange64, INT64* location, INT64 value, INT64 comparand); - static FCDECL2_IV(float, ExchangeFloat, float *location, float value); - static FCDECL2_IV(double, ExchangeDouble, double *location, double value); - static FCDECL3_IVV(float, CompareExchangeFloat, float *location, float value, float comparand); - static FCDECL3_IVV(double, CompareExchangeDouble, double *location, double value, double comparand); static FCDECL2(LPVOID, ExchangeObject, LPVOID* location, LPVOID value); static FCDECL3(LPVOID, CompareExchangeObject, LPVOID* location, LPVOID value, LPVOID comparand); static FCDECL2(INT32, ExchangeAdd32, INT32 *location, INT32 value); diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index 75436d56c0976d..9fc399c31cd5a3 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -509,13 +509,9 @@ FCFuncEnd() FCFuncStart(gInterlockedFuncs) FCFuncElementSig("Exchange", &gsig_SM_RefInt_Int_RetInt, COMInterlocked::Exchange) FCFuncElementSig("Exchange", &gsig_SM_RefLong_Long_RetLong, COMInterlocked::Exchange64) - FCFuncElementSig("Exchange", &gsig_SM_RefDbl_Dbl_RetDbl, COMInterlocked::ExchangeDouble) - FCFuncElementSig("Exchange", &gsig_SM_RefFlt_Flt_RetFlt, COMInterlocked::ExchangeFloat) FCFuncElementSig("Exchange", &gsig_SM_RefObj_Obj_RetObj, COMInterlocked::ExchangeObject) FCFuncElementSig("CompareExchange", &gsig_SM_RefInt_Int_Int_RetInt, COMInterlocked::CompareExchange) FCFuncElementSig("CompareExchange", &gsig_SM_RefLong_Long_Long_RetLong, COMInterlocked::CompareExchange64) - FCFuncElementSig("CompareExchange", &gsig_SM_RefDbl_Dbl_Dbl_RetDbl, COMInterlocked::CompareExchangeDouble) - FCFuncElementSig("CompareExchange", &gsig_SM_RefFlt_Flt_Flt_RetFlt, COMInterlocked::CompareExchangeFloat) FCFuncElementSig("CompareExchange", &gsig_SM_RefObj_Obj_Obj_RetObj, COMInterlocked::CompareExchangeObject) FCFuncElementSig("ExchangeAdd", &gsig_SM_RefInt_Int_RetInt, COMInterlocked::ExchangeAdd32) FCFuncElementSig("ExchangeAdd", &gsig_SM_RefLong_Long_RetLong, COMInterlocked::ExchangeAdd64) 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 7c9b9c24659e13..f40564b6746e63 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Interlocked.cs @@ -69,6 +69,24 @@ public static uint Exchange(ref uint location1, uint value) => public static ulong Exchange(ref ulong location1, ulong value) => (ulong)Exchange(ref Unsafe.As(ref location1), (long)value); + /// Sets a single-precision floating point number to a specified value and returns the original value, as an atomic operation. + /// The variable to set to the specified value. + /// The value to which the parameter is set. + /// The original value of . + /// The address of location1 is a null pointer. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Exchange(ref float location1, float value) + => Unsafe.BitCast(Exchange(ref Unsafe.As(ref location1), Unsafe.BitCast(value))); + + /// Sets a double-precision floating point number to a specified value and returns the original value, as an atomic operation. + /// The variable to set to the specified value. + /// The value to which the parameter is set. + /// The original value of . + /// The address of location1 is a null pointer. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Exchange(ref double location1, double value) + => Unsafe.BitCast(Exchange(ref Unsafe.As(ref location1), Unsafe.BitCast(value))); + /// Sets a platform-specific handle or pointer to a specified value and returns the original value, as an atomic operation. /// The variable to set to the specified value. /// The value to which the parameter is set. @@ -126,6 +144,26 @@ public static uint CompareExchange(ref uint location1, uint value, uint comparan public static ulong CompareExchange(ref ulong location1, ulong value, ulong comparand) => (ulong)CompareExchange(ref Unsafe.As(ref location1), (long)value, (long)comparand); + /// Compares two single-precision floating point numbers for equality and, if they are equal, replaces the first value. + /// The destination, whose value is compared with and possibly replaced. + /// The value that replaces the destination value if the comparison results in equality. + /// The value that is compared to the value at . + /// The original value in . + /// The address of is a null pointer. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float CompareExchange(ref float location1, float value, float comparand) + => Unsafe.BitCast(CompareExchange(ref Unsafe.As(ref location1), Unsafe.BitCast(value), Unsafe.BitCast(comparand))); + + /// Compares two double-precision floating point numbers for equality and, if they are equal, replaces the first value. + /// The destination, whose value is compared with and possibly replaced. + /// The value that replaces the destination value if the comparison results in equality. + /// The value that is compared to the value at . + /// The original value in . + /// The address of is a null pointer. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double CompareExchange(ref double location1, double value, double comparand) + => Unsafe.BitCast(CompareExchange(ref Unsafe.As(ref location1), Unsafe.BitCast(value), Unsafe.BitCast(comparand))); + /// Compares two platform-specific handles or pointers for equality and, if they are equal, replaces the first one. /// The destination , whose value is compared with the value of and possibly replaced by . /// The that replaces the destination value if the comparison results in equality. diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/Interlocked.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Threading/Interlocked.Mono.cs index bc18986464eef6..b5282beaa785d9 100644 --- a/src/mono/System.Private.CoreLib/src/System/Threading/Interlocked.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Threading/Interlocked.Mono.cs @@ -37,9 +37,6 @@ public static partial class Interlocked return result; } - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern float CompareExchange(ref float location1, float value, float comparand); - [Intrinsic] [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern int Decrement(ref int location); @@ -72,16 +69,9 @@ public static partial class Interlocked return result; } - [Intrinsic] - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern float Exchange(ref float location1, float value); - [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long CompareExchange(ref long location1, long value, long comparand); - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern double CompareExchange(ref double location1, double value, double comparand); - [return: NotNullIfNotNull(nameof(location1))] [Intrinsic] public static T CompareExchange(ref T location1, T value, T comparand) where T : class? @@ -110,10 +100,6 @@ public static T CompareExchange(ref T location1, T value, T comparand) where [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Exchange(ref long location1, long value); - [Intrinsic] - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern double Exchange(ref double location1, double value); - [return: NotNullIfNotNull(nameof(location1))] [Intrinsic] public static T Exchange([NotNullIfNotNull(nameof(value))] ref T location1, T value) where T : class? diff --git a/src/mono/mono/metadata/icall-def.h b/src/mono/mono/metadata/icall-def.h index 3fc1a6e1cebf62..a2ed4f55f80891 100644 --- a/src/mono/mono/metadata/icall-def.h +++ b/src/mono/mono/metadata/icall-def.h @@ -549,19 +549,15 @@ HANDLES(STRING_11, "InternalIsInterned", ves_icall_System_String_InternalIsInter ICALL_TYPE(ILOCK, "System.Threading.Interlocked", ILOCK_1) NOHANDLES(ICALL(ILOCK_1, "Add(int&,int)", ves_icall_System_Threading_Interlocked_Add_Int)) NOHANDLES(ICALL(ILOCK_2, "Add(long&,long)", ves_icall_System_Threading_Interlocked_Add_Long)) -NOHANDLES(ICALL(ILOCK_4, "CompareExchange(double&,double,double)", ves_icall_System_Threading_Interlocked_CompareExchange_Double)) NOHANDLES(ICALL(ILOCK_5, "CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int)) NOHANDLES(ICALL(ILOCK_6, "CompareExchange(int&,int,int,bool&)", ves_icall_System_Threading_Interlocked_CompareExchange_Int_Success)) NOHANDLES(ICALL(ILOCK_8, "CompareExchange(long&,long,long)", ves_icall_System_Threading_Interlocked_CompareExchange_Long)) NOHANDLES(ICALL(ILOCK_9, "CompareExchange(object&,object&,object&,object&)", ves_icall_System_Threading_Interlocked_CompareExchange_Object)) -NOHANDLES(ICALL(ILOCK_10, "CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single)) NOHANDLES(ICALL(ILOCK_11, "Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int)) NOHANDLES(ICALL(ILOCK_12, "Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long)) -NOHANDLES(ICALL(ILOCK_14, "Exchange(double&,double)", ves_icall_System_Threading_Interlocked_Exchange_Double)) NOHANDLES(ICALL(ILOCK_15, "Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int)) NOHANDLES(ICALL(ILOCK_17, "Exchange(long&,long)", ves_icall_System_Threading_Interlocked_Exchange_Long)) NOHANDLES(ICALL(ILOCK_18, "Exchange(object&,object&,object&)", ves_icall_System_Threading_Interlocked_Exchange_Object)) -NOHANDLES(ICALL(ILOCK_19, "Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single)) NOHANDLES(ICALL(ILOCK_20, "Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int)) NOHANDLES(ICALL(ILOCK_21, "Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long)) NOHANDLES(ICALL(ILOCK_22, "MemoryBarrierProcessWide", ves_icall_System_Threading_Interlocked_MemoryBarrierProcessWide)) diff --git a/src/mono/mono/metadata/threads-types.h b/src/mono/mono/metadata/threads-types.h index 5e89f84bef211a..c1436094559c8c 100644 --- a/src/mono/mono/metadata/threads-types.h +++ b/src/mono/mono/metadata/threads-types.h @@ -145,12 +145,6 @@ gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gi ICALL_EXPORT void ves_icall_System_Threading_Interlocked_Exchange_Object (MonoObject *volatile*location, MonoObject *volatile*value, MonoObject *volatile*res); -ICALL_EXPORT -gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value); - -ICALL_EXPORT -gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value); - ICALL_EXPORT gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand); @@ -163,12 +157,6 @@ gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *locat ICALL_EXPORT void ves_icall_System_Threading_Interlocked_CompareExchange_Object (MonoObject *volatile*location, MonoObject *volatile*value, MonoObject *volatile*comparand, MonoObject *volatile*res); -ICALL_EXPORT -gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand); - -ICALL_EXPORT -gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand); - ICALL_EXPORT gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value); diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index 0788d9ccdac13c..7cde95a9dc0b1a 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -116,16 +116,6 @@ mono_native_thread_join_handle (HANDLE thread_handle, gboolean close_handle); #define LOCK_THREAD(thread) lock_thread((thread)) #define UNLOCK_THREAD(thread) unlock_thread((thread)) -typedef union { - gint32 ival; - gfloat fval; -} IntFloatUnion; - -typedef union { - gint64 ival; - gdouble fval; -} LongDoubleUnion; - typedef struct _StaticDataFreeList StaticDataFreeList; struct _StaticDataFreeList { StaticDataFreeList *next; @@ -2178,18 +2168,6 @@ ves_icall_System_Threading_Interlocked_Exchange_Object (MonoObject *volatile*loc mono_gc_wbarrier_generic_nostore_internal ((gpointer)location); // FIXME volatile } -gfloat ves_icall_System_Threading_Interlocked_Exchange_Single (gfloat *location, gfloat value) -{ - IntFloatUnion val, ret; - if (G_UNLIKELY (!location)) - return (gfloat)set_pending_null_reference_exception (); - - val.fval = value; - ret.ival = mono_atomic_xchg_i32((gint32 *) location, val.ival); - - return ret.fval; -} - gint64 ves_icall_System_Threading_Interlocked_Exchange_Long (gint64 *location, gint64 value) { @@ -2209,19 +2187,6 @@ ves_icall_System_Threading_Interlocked_Exchange_Long (gint64 *location, gint64 v return mono_atomic_xchg_i64 (location, value); } -gdouble -ves_icall_System_Threading_Interlocked_Exchange_Double (gdouble *location, gdouble value) -{ - LongDoubleUnion val, ret; - if (G_UNLIKELY (!location)) - return (gdouble)set_pending_null_reference_exception (); - - val.fval = value; - ret.ival = (gint64)mono_atomic_xchg_i64((gint64 *) location, val.ival); - - return ret.fval; -} - gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand) { if (G_UNLIKELY (!location)) @@ -2261,46 +2226,6 @@ ves_icall_System_Threading_Interlocked_CompareExchange_Object (MonoObject *volat mono_gc_wbarrier_generic_nostore_internal ((gpointer)location); // FIXME volatile } -gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single (gfloat *location, gfloat value, gfloat comparand) -{ - IntFloatUnion val, ret, cmp; - if (G_UNLIKELY (!location)) - return (gfloat)set_pending_null_reference_exception (); - - val.fval = value; - cmp.fval = comparand; - ret.ival = mono_atomic_cas_i32((gint32 *) location, val.ival, cmp.ival); - - return ret.fval; -} - -gdouble -ves_icall_System_Threading_Interlocked_CompareExchange_Double (gdouble *location, gdouble value, gdouble comparand) -{ - if (G_UNLIKELY (!location)) - return (gdouble)set_pending_null_reference_exception (); - -#if SIZEOF_VOID_P == 8 - LongDoubleUnion val, comp, ret; - - val.fval = value; - comp.fval = comparand; - ret.ival = (gint64)mono_atomic_cas_ptr((gpointer *) location, (gpointer)val.ival, (gpointer)comp.ival); - - return ret.fval; -#else - gdouble old; - - mono_interlocked_lock (); - old = *location; - if (old == comparand) - *location = value; - mono_interlocked_unlock (); - - return old; -#endif -} - gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long (gint64 *location, gint64 value, gint64 comparand) {