Skip to content

Commit 834b897

Browse files
authored
Apply suggestions from code review
1 parent 802caa0 commit 834b897

File tree

1 file changed

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

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,13 @@ public static unsafe T And<T>(ref T location1, T value) where T : struct
652652
{
653653
// Only integer primitive types and enum types backed by integer types are supported.
654654
// Floating-point types and floating-point backed enums are not supported.
655-
if ((!typeof(T).IsPrimitive && !typeof(T).IsEnum) ||
656-
(Type.GetTypeCode(typeof(T)) == TypeCode.Single) ||
657-
(Type.GetTypeCode(typeof(T)) == TypeCode.Double))
655+
if (!typeof(T).IsPrimitive || typeof(T) == typeof(float) || typeof(T) == typeof(double))
656+
{
657+
if (!typeof(T).IsEnum || typeof(T).GetEnumUnderlyingType() == typeof(float) || typeof(T).GetEnumUnderlyingType() == typeof(double))
658658
{
659659
throw new NotSupportedException(SR.NotSupported_IntegerEnumOrPrimitiveTypeRequired);
660660
}
661+
}
661662

662663
// For 1-byte and 2-byte types, we need to use CompareExchange-based implementations
663664
// because there are no direct atomic And operations for these sizes.
@@ -795,12 +796,13 @@ public static unsafe T Or<T>(ref T location1, T value) where T : struct
795796
{
796797
// Only integer primitive types and enum types backed by integer types are supported.
797798
// Floating-point types and floating-point backed enums are not supported.
798-
if ((!typeof(T).IsPrimitive && !typeof(T).IsEnum) ||
799-
(Type.GetTypeCode(typeof(T)) == TypeCode.Single) ||
800-
(Type.GetTypeCode(typeof(T)) == TypeCode.Double))
799+
if (!typeof(T).IsPrimitive || typeof(T) == typeof(float) || typeof(T) == typeof(double))
800+
{
801+
if (!typeof(T).IsEnum || typeof(T).GetEnumUnderlyingType() == typeof(float) || typeof(T).GetEnumUnderlyingType() == typeof(double))
801802
{
802803
throw new NotSupportedException(SR.NotSupported_IntegerEnumOrPrimitiveTypeRequired);
803804
}
805+
}
804806

805807
// For 1-byte and 2-byte types, we need to use CompareExchange-based implementations
806808
// because there are no direct atomic Or operations for these sizes.

0 commit comments

Comments
 (0)