提交 f26bf6ad 编写于 作者: S Sam Harwell

Mark types as non-copyable

上级 6d9567b2
......@@ -16,6 +16,7 @@ internal static ReadLockExiter DisposableRead(this ReaderWriterLockSlim @lock)
return new ReadLockExiter(@lock);
}
[NonCopyable]
internal readonly struct ReadLockExiter : IDisposable
{
private readonly ReaderWriterLockSlim _lock;
......@@ -37,6 +38,7 @@ internal static UpgradeableReadLockExiter DisposableUpgradeableRead(this ReaderW
return new UpgradeableReadLockExiter(@lock);
}
[NonCopyable]
internal readonly struct UpgradeableReadLockExiter : IDisposable
{
private readonly ReaderWriterLockSlim _lock;
......@@ -68,6 +70,7 @@ internal static WriteLockExiter DisposableWrite(this ReaderWriterLockSlim @lock)
return new WriteLockExiter(@lock);
}
[NonCopyable]
internal readonly struct WriteLockExiter : IDisposable
{
private readonly ReaderWriterLockSlim _lock;
......
......@@ -25,6 +25,7 @@ public static async ValueTask<SemaphoreDisposer> DisposableWaitAsync(this Semaph
return new SemaphoreDisposer(semaphore);
}
[NonCopyable]
internal struct SemaphoreDisposer : IDisposable
{
private readonly SemaphoreSlim _semaphore;
......
......@@ -313,6 +313,7 @@ public static Releaser GetPooledAction<TArg>(Action<TArg> unboundAction, TArg ar
/// omitted, the object will not be returned to the pool. The behavior of this type if <see cref="Dispose"/> is
/// called multiple times is undefined.</para>
/// </remarks>
[NonCopyable]
public struct Releaser : IDisposable
{
private readonly Poolable _pooledObject;
......@@ -416,5 +417,10 @@ private sealed class FuncWithBoundArgument<T1, T2, T3, TArg, TResult>
protected override Func<T1, T2, T3, TResult> Bind()
=> (arg1, arg2, arg3) => UnboundDelegate(arg1, arg2, arg3, Argument);
}
[AttributeUsage(AttributeTargets.Struct)]
private sealed class NonCopyableAttribute : Attribute
{
}
}
}
......@@ -37,6 +37,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Compilers\Core\Portable\InternalUtilities\NonCopyableAttribute.cs" Link="Utilities\NonCopyableAttribute.cs" />
<Compile Include="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\TestHooks\IExpeditableDelaySource.cs" Link="Utilities\IExpeditableDelaySource.cs" />
<Compile Include="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\Contract.cs" Link="Utilities\Contract.cs" />
<Compile Include="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\TaskExtensions.cs" Link="Utilities\TaskExtensions.cs" />
......
......@@ -6,6 +6,7 @@
using System;
using System.Runtime.InteropServices;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Shared.Extensions
{
......@@ -13,6 +14,7 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions
/// Represents a lease of a <see cref="SafeHandle"/>.
/// </summary>
/// <seealso cref="SafeHandleExtensions.Lease"/>
[NonCopyable]
internal readonly struct SafeHandleLease : IDisposable
{
private readonly SafeHandle? _handle;
......
......@@ -31,10 +31,16 @@ public sqlite3_blob DangerousGetWrapper()
protected override bool ReleaseHandle()
{
using var _ = _lease;
var result = (Result)raw.sqlite3_blob_close(_wrapper);
SetHandle(IntPtr.Zero);
return result == Result.OK;
try
{
var result = (Result)raw.sqlite3_blob_close(_wrapper);
SetHandle(IntPtr.Zero);
return result == Result.OK;
}
finally
{
_lease.Dispose();
}
}
}
}
......@@ -31,10 +31,16 @@ public sqlite3_stmt DangerousGetWrapper()
protected override bool ReleaseHandle()
{
using var _ = _lease;
var result = (Result)raw.sqlite3_finalize(_wrapper);
SetHandle(IntPtr.Zero);
return result == Result.OK;
try
{
var result = (Result)raw.sqlite3_finalize(_wrapper);
SetHandle(IntPtr.Zero);
return result == Result.OK;
}
finally
{
_lease.Dispose();
}
}
}
}
......@@ -14,6 +14,7 @@
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\ExceptionUtilities.cs" Link="InternalUtilities\ExceptionUtilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\IReadOnlySet.cs" Link="InternalUtilities\IReadOnlySet.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\KeyValuePairUtil.cs" Link="InternalUtilities\KeyValuePairUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\NonCopyableAttribute.cs" Link="InternalUtilities\NonCopyableAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\NonDefaultableAttribute.cs" Link="InternalUtilities\NonDefaultableAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\NullableAttributes.cs" Link="InternalUtilities\NullableAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\ReferenceEqualityComparer.cs" Link="InternalUtilities\ReferenceEqualityComparer.cs" />
......
......@@ -3,9 +3,11 @@
// See the LICENSE file in the project root for more information.
using System;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.PooledObjects
{
[NonCopyable]
internal readonly struct PooledDisposer<TPoolable> : IDisposable
where TPoolable : class, IPooled
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册