Improve ToggleRef release overhead.

Candidate patch provided by Andres in pull request #17.

* glib/Object.cs: use ToggleRef.Dispose.
* glib/ToggleRef.cs: implement IDisposable and expose former Free
    functionality as Dispose().  Free is now private non-lock taking
    called by Dispose and the idle queue handler.
This commit is contained in:
Mike Kestner 2011-07-29 13:33:02 -05:00
parent 10f4f03943
commit 4f42fb77fb
2 changed files with 9 additions and 5 deletions

View File

@ -69,7 +69,7 @@ namespace GLib {
return; return;
if (disposing) if (disposing)
tref.Free (); tref.Dispose ();
else else
tref.QueueUnref (); tref.QueueUnref ();
} }
@ -429,7 +429,7 @@ namespace GLib {
if (handle != IntPtr.Zero) { if (handle != IntPtr.Zero) {
Objects.Remove (handle); Objects.Remove (handle);
if (tref != null) { if (tref != null) {
tref.Free (); tref.Dispose ();
tref = null; tref = null;
} }
} }

View File

@ -25,7 +25,7 @@ using System.Runtime.InteropServices;
namespace GLib { namespace GLib {
internal class ToggleRef { internal class ToggleRef : IDisposable {
bool hardened; bool hardened;
IntPtr handle; IntPtr handle;
@ -57,12 +57,16 @@ namespace GLib {
} }
} }
public void Free () public void Dispose ()
{ {
lock (PendingDestroys) { lock (PendingDestroys) {
PendingDestroys.Remove (this); PendingDestroys.Remove (this);
} }
Free ();
}
void Free ()
{
if (hardened) if (hardened)
g_object_unref (handle); g_object_unref (handle);
else else