From 9ef9db660fd7952d7aed48278d4cdf6b1deeebbd Mon Sep 17 00:00:00 2001 From: wj32 Date: Sat, 4 Jul 2009 07:53:34 +0000 Subject: [PATCH] fixed BaseObject bugs git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1521 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- trunk/ProcessHacker.Common/Objects/BaseObject.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/trunk/ProcessHacker.Common/Objects/BaseObject.cs b/trunk/ProcessHacker.Common/Objects/BaseObject.cs index eea225207..dc8c04d2a 100644 --- a/trunk/ProcessHacker.Common/Objects/BaseObject.cs +++ b/trunk/ProcessHacker.Common/Objects/BaseObject.cs @@ -144,7 +144,7 @@ namespace ProcessHacker.Common.Objects // Don't need to finalize the object if it doesn't need to be disposed. if (!_owned) - GC.SuppressFinalize(this); + this.DisableFinalizer(); Interlocked.Increment(ref _createdCount); #if DEBUG @@ -161,8 +161,7 @@ namespace ProcessHacker.Common.Objects // Get rid of GC ownership if still present. this.Dispose(false); // Zero the weak reference count. - this.Dereference(_weakRefCount, false); - _weakRefCount = 0; + this.ClearWeakReferences(); } /// @@ -287,6 +286,15 @@ namespace ProcessHacker.Common.Objects get { return Thread.VolatileRead(ref _weakRefCount); } } + /// + /// Removes all weak references. + /// + private void ClearWeakReferences() + { + this.Dereference(_weakRefCount, false); + _weakRefCount = 0; + } + /// /// Disables the finalizer if it is not already disabled. /// @@ -473,6 +481,7 @@ namespace ProcessHacker.Common.Objects return 0; Thread.BeginCriticalRegion(); + _refMutex.Acquire(); try { @@ -482,6 +491,7 @@ namespace ProcessHacker.Common.Objects } finally { + _refMutex.Release(); Thread.EndCriticalRegion(); } }