diff options
author | Stephen Toub <stoub@microsoft.com> | 2019-05-28 06:04:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 06:04:13 -0400 |
commit | 4a1275434fff99206f2a28f5f0e87f124069eb7f (patch) | |
tree | 4e5c7667e29c969179a965048f2452f4d4bad3ad /src/System.Private.CoreLib/src/System/Threading | |
parent | bb75edbac9c40034b6683c17d86057ee9bf4192d (diff) | |
download | coreclr-4a1275434fff99206f2a28f5f0e87f124069eb7f.tar.gz coreclr-4a1275434fff99206f2a28f5f0e87f124069eb7f.tar.bz2 coreclr-4a1275434fff99206f2a28f5f0e87f124069eb7f.zip |
Add and apply nullable attributes (#24679)
* Add and apply nullable attributes
* Adapt to API review decisions
* Address PR feedback
Diffstat (limited to 'src/System.Private.CoreLib/src/System/Threading')
3 files changed, 10 insertions, 5 deletions
diff --git a/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs b/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs index ed6829e228..f23942ee29 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs @@ -5,6 +5,7 @@ using System.Runtime.CompilerServices; using Internal.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Diagnostics.CodeAnalysis; namespace System.Threading { @@ -59,7 +60,8 @@ namespace System.Threading public static extern double Exchange(ref double location1, double value); [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern object? Exchange(ref object? location1, object? value); + [return: NotNullIfNotNull("value")] + public static extern object? Exchange([NotNullIfNotNull("value")] ref object? location1, object? value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern IntPtr Exchange(ref IntPtr location1, IntPtr value); @@ -67,7 +69,8 @@ namespace System.Threading // This whole method reduces to a single call to Exchange(ref object, object) but // the JIT thinks that it will generate more native code than it actually does. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T Exchange<T>(ref T location1, T value) where T : class? + [return: NotNullIfNotNull("value")] + public static T Exchange<T>([NotNullIfNotNull("value")] ref T location1, T value) where T : class? { return Unsafe.As<T>(Exchange(ref Unsafe.As<T, object?>(ref location1), value)); } diff --git a/src/System.Private.CoreLib/src/System/Threading/Monitor.cs b/src/System.Private.CoreLib/src/System/Threading/Monitor.cs index 4385bf9992..1783d4d685 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Monitor.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Monitor.cs @@ -21,6 +21,7 @@ using System.Runtime.ConstrainedExecution; using System.Runtime.Versioning; using System.Diagnostics; using System.Runtime.InteropServices; +using System.Diagnostics.CodeAnalysis; namespace System.Threading { @@ -52,6 +53,7 @@ namespace System.Threading Debug.Assert(lockTaken); } + [DoesNotReturn] private static void ThrowLockTakenException() { throw new ArgumentException(SR.Argument_MustBeFalse, "lockTaken"); diff --git a/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index 53d47b98cf..ec82665b64 100644 --- a/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -52,7 +52,7 @@ namespace System.Threading m_internalWaitObject = waitObject; if (waitObject != null) { - m_internalWaitObject.SafeWaitHandle!.DangerousAddRef(ref bReleaseNeeded); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2384 + m_internalWaitObject.SafeWaitHandle.DangerousAddRef(ref bReleaseNeeded); } } @@ -82,7 +82,7 @@ namespace System.Threading if (bReleaseNeeded) { Debug.Assert(m_internalWaitObject != null, "Must be non-null for bReleaseNeeded to be true"); - m_internalWaitObject.SafeWaitHandle!.DangerousRelease(); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2384 + m_internalWaitObject.SafeWaitHandle.DangerousRelease(); bReleaseNeeded = false; } // if result not true don't release/suppress here so finalizer can make another attempt @@ -144,7 +144,7 @@ namespace System.Threading if (bReleaseNeeded) { Debug.Assert(m_internalWaitObject != null, "Must be non-null for bReleaseNeeded to be true"); - m_internalWaitObject.SafeWaitHandle!.DangerousRelease(); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2384 + m_internalWaitObject.SafeWaitHandle.DangerousRelease(); bReleaseNeeded = false; } SetHandle(InvalidHandle); |