You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
5 years ago
|
#if FAT
|
||
|
|
||
|
using System;
|
||
|
|
||
|
using LinqInternal.Core;
|
||
|
|
||
|
namespace LinqInternal.Threading
|
||
|
{
|
||
|
[System.Diagnostics.DebuggerNonUserCode]
|
||
|
internal sealed partial class CriticalDisposable
|
||
|
#if !NETCOREAPP1_1
|
||
|
: System.Runtime.ConstrainedExecution.CriticalFinalizerObject
|
||
|
#endif
|
||
|
{
|
||
|
private Action _release;
|
||
|
|
||
|
private CriticalDisposable(Action release)
|
||
|
{
|
||
|
if (release == null)
|
||
|
{
|
||
|
throw new ArgumentNullException("release");
|
||
|
}
|
||
|
_release = release;
|
||
|
}
|
||
|
|
||
|
public static CriticalDisposable Create(Action release)
|
||
|
{
|
||
|
return new CriticalDisposable(release);
|
||
|
}
|
||
|
|
||
|
public bool Dispose(Func<bool> condition)
|
||
|
{
|
||
|
if (condition == null)
|
||
|
{
|
||
|
throw new ArgumentNullException("condition");
|
||
|
}
|
||
|
Func<bool> temp = condition;
|
||
|
return DisposedConditional
|
||
|
(
|
||
|
FuncHelper.GetFallacyFunc(),
|
||
|
() =>
|
||
|
{
|
||
|
if (condition.Invoke())
|
||
|
{
|
||
|
Dispose();
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|