checkpoint collections
This commit is contained in:
46
SafeListHandle.cs
Normal file
46
SafeListHandle.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
|
||||
namespace Foodsoft.Alpm
|
||||
{
|
||||
internal struct ListRef : CriticalFinalIDisposable
|
||||
{
|
||||
public SafeAlpmHandle SafeAlpmHandle
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[PrePrepareMethod]
|
||||
get;
|
||||
}
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), PrePrepareMethod]
|
||||
public ListRef(SafeAlpmHandle handle)
|
||||
{
|
||||
SafeAlpmHandle = null!;
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try { }
|
||||
finally
|
||||
{
|
||||
SafeAlpmHandle = handle;
|
||||
var success = false;
|
||||
handle.DangerousAddRef(ref success);
|
||||
if (success)
|
||||
SafeAlpmHandle = handle;
|
||||
else
|
||||
{
|
||||
SafeAlpmHandle = null!;
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~ListRef()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user