//
//
-#if NET_2_0
using System;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
int refcount = 0;
bool owns_handle;
+#if NET_2_1
+ protected SafeHandle ()
+ {
+ throw new NotImplementedException ();
+ }
+#endif
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeHandle (IntPtr invalidHandleValue, bool ownsHandle)
{
if (newcount == 0 && owns_handle && !IsInvalid){
ReleaseHandle ();
handle = invalid_handle_value;
+ refcount = -1;
}
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
public void DangerousAddRef (ref bool success)
{
- if (refcount == 0)
+ if (refcount <= 0)
throw new ObjectDisposedException (GetType ().FullName);
int newcount, current;
current = refcount;
newcount = current + 1;
- if (handle == invalid_handle_value || current == 0){
+ if (current <= 0){
//
// In MS, calling sf.Close () followed by a call
// to P/Invoke with SafeHandles throws this, but
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public IntPtr DangerousGetHandle ()
{
- if (refcount == 0){
+ if (refcount <= 0){
throw new ObjectDisposedException (GetType ().FullName);
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public void DangerousRelease ()
{
- if (refcount == 0)
+ if (refcount <= 0)
throw new ObjectDisposedException (GetType ().FullName);
int newcount, current;
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
- public virtual void Dispose ()
+ public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
public bool IsClosed {
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
get {
- return refcount == 0;
+ return refcount <= 0;
}
}
}
}
}
-#endif