diff --git a/trunk/ProcessHacker.Common/Objects/BaseObject.cs b/trunk/ProcessHacker.Common/Objects/BaseObject.cs index dc18dbb80..2770fcbd2 100644 --- a/trunk/ProcessHacker.Common/Objects/BaseObject.cs +++ b/trunk/ProcessHacker.Common/Objects/BaseObject.cs @@ -20,9 +20,12 @@ * along with Process Hacker. If not, see . */ +#define ENABLE_STATISTICS +//#define EXTENDED_FINALIZER + using System; +using System.ComponentModel; using System.Threading; -using ProcessHacker.Common.Threading; namespace ProcessHacker.Common.Objects { @@ -122,13 +125,15 @@ namespace ProcessHacker.Common.Objects /// private int _refCount = 1; /// - /// Whether the finalizer will run. - /// - private int _finalizerRegistered = 1; - /// /// Whether the object has been freed. /// private volatile bool _disposed = false; +#if EXTENDED_FINALIZER + /// + /// Whether the finalizer will run. + /// + private int _finalizerRegistered = 1; +#endif /// /// Initializes a disposable object. @@ -148,25 +153,38 @@ namespace ProcessHacker.Common.Objects // Don't need to finalize the object if it doesn't need to be disposed. if (!_owned) { +#if EXTENDED_FINALIZER this.DisableFinalizer(); +#else + GC.SuppressFinalize(this); +#endif _ownedByGc = 0; _refCount = 0; } +#if ENABLE_STATISTICS Interlocked.Increment(ref _createdCount); +#endif + #if DEBUG _creationStackTrace = Environment.StackTrace; #endif } /// - /// Ensures that the GC does not own the object and destroys - /// all weak references. + /// Ensures that the GC does not own the object. /// ~BaseObject() { // Get rid of GC ownership if still present. this.Dispose(false); + +#if ENABLE_STATISTICS + Interlocked.Increment(ref _finalizedCount); + // Dispose just incremented this value, but it + // shouldn't have been incremented. + Interlocked.Decrement(ref _disposedCount); +#endif } /// @@ -203,18 +221,23 @@ namespace ProcessHacker.Common.Objects // Disable the finalizer. if (managed) + { +#if EXTENDED_FINALIZER this.DisableFinalizer(); +#else + GC.SuppressFinalize(this); +#endif + } +#if ENABLE_STATISTICS // Stats. - if (managed) - Interlocked.Increment(ref _disposedCount); - else - Interlocked.Increment(ref _finalizedCount); + Interlocked.Increment(ref _disposedCount); // The dereferenced count should count the number of times // the user has called Dereference, so decrement it // because we just called it. Interlocked.Decrement(ref _dereferencedCount); +#endif } } finally @@ -225,7 +248,8 @@ namespace ProcessHacker.Common.Objects /// /// Queues the object for disposal in the current delayed release pool. - /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] public void DisposeDelayed() { DelayedReleasePool.CurrentPool.AddDispose(this); @@ -274,6 +298,7 @@ namespace ProcessHacker.Common.Objects get { return Thread.VolatileRead(ref _refCount); } } +#if EXTENDED_FINALIZER /// /// Disables the finalizer if it is not already disabled. /// @@ -288,6 +313,7 @@ namespace ProcessHacker.Common.Objects GC.SuppressFinalize(this); } } +#endif /// /// Declares that the object should no longer be owned. @@ -297,13 +323,19 @@ namespace ProcessHacker.Common.Objects if (dispose) this.Dispose(); +#if EXTENDED_FINALIZER this.DisableFinalizer(); +#else + GC.SuppressFinalize(this); +#endif _owned = false; +#if ENABLE_STATISTICS // If the object didn't get disposed, pretend the object // never got created. if (!dispose) Interlocked.Decrement(ref _createdCount); +#endif } /// @@ -371,8 +403,10 @@ namespace ProcessHacker.Common.Objects if (!_owned) return 0; +#if ENABLE_STATISTICS // Statistics. Interlocked.Add(ref _dereferencedCount, count); +#endif // Decrease the reference count. int newRefCount = Interlocked.Add(ref _refCount, -count); @@ -389,7 +423,10 @@ namespace ProcessHacker.Common.Objects this.DisposeObject(managed); // Prevent the object from being disposed twice. _disposed = true; + +#if ENABLE_STATISTICS Interlocked.Increment(ref _freedCount); +#endif } return newRefCount; @@ -403,11 +440,13 @@ namespace ProcessHacker.Common.Objects /// /// Queues the object for dereferencing in the current delayed release pool. /// + [EditorBrowsable(EditorBrowsableState.Never)] public void DereferenceDelayed() { DelayedReleasePool.CurrentPool.AddDereference(this); } +#if EXTENDED_FINALIZER /// /// Enables the finalizer if it is not already enabled. /// @@ -422,6 +461,7 @@ namespace ProcessHacker.Common.Objects GC.ReRegisterForFinalize(this); } } +#endif /// /// Increments the reference count of the object. @@ -454,7 +494,9 @@ namespace ProcessHacker.Common.Objects if (count < 0) throw new ArgumentException("Cannot reference a negative number of times."); +#if ENABLE_STATISTICS Interlocked.Add(ref _referencedCount, count); +#endif return Interlocked.Add(ref _refCount, count); } diff --git a/trunk/ProcessHacker.Native/Api/NativeFunctions.cs b/trunk/ProcessHacker.Native/Api/NativeFunctions.cs index d663767bb..0316b5fce 100644 --- a/trunk/ProcessHacker.Native/Api/NativeFunctions.cs +++ b/trunk/ProcessHacker.Native/Api/NativeFunctions.cs @@ -21,6 +21,7 @@ * along with Process Hacker. If not, see . */ +// Parameter 'parameter' has no matching param tag in the XML comment for 'parameter' (but other parameters do) #pragma warning disable 1573 using System; diff --git a/trunk/ProcessHacker.Native/KProcessHacker.cs b/trunk/ProcessHacker.Native/KProcessHacker.cs index dcf88e24a..fa568d026 100644 --- a/trunk/ProcessHacker.Native/KProcessHacker.cs +++ b/trunk/ProcessHacker.Native/KProcessHacker.cs @@ -20,6 +20,7 @@ * along with Process Hacker. If not, see . */ +// The private field 'field' is assigned but its value is never used #pragma warning disable 0414 using System; diff --git a/trunk/ProcessHacker.Native/Windows.cs b/trunk/ProcessHacker.Native/Windows.cs index 759c2d9c6..5421d9386 100644 --- a/trunk/ProcessHacker.Native/Windows.cs +++ b/trunk/ProcessHacker.Native/Windows.cs @@ -21,6 +21,7 @@ * along with Process Hacker. If not, see . */ +// 'member' is obsolete: 'text' #pragma warning disable 0618 using System; diff --git a/trunk/ProcessHacker/Components/ProcessTree/ProcessTreeModel.cs b/trunk/ProcessHacker/Components/ProcessTree/ProcessTreeModel.cs index 26184045e..25c784404 100644 --- a/trunk/ProcessHacker/Components/ProcessTree/ProcessTreeModel.cs +++ b/trunk/ProcessHacker/Components/ProcessTree/ProcessTreeModel.cs @@ -20,6 +20,7 @@ * along with Process Hacker. If not, see . */ +// The event 'event' is never used #pragma warning disable 0067 using System; diff --git a/trunk/ProcessHacker/Providers/NetworkProvider.cs b/trunk/ProcessHacker/Providers/NetworkProvider.cs index fceef99a9..dcdf2f680 100644 --- a/trunk/ProcessHacker/Providers/NetworkProvider.cs +++ b/trunk/ProcessHacker/Providers/NetworkProvider.cs @@ -20,6 +20,7 @@ * along with Process Hacker. If not, see . */ +// 'member' is obsolete: 'text' #pragma warning disable 0618 using System;