From 971b3091201d7431f920d8b7247d1ab41bc97abf Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Fri, 17 Oct 2003 19:17:19 +0000 Subject: [PATCH] 2003-10-17 Gonzalo Paniagua Javier * gtk/ThreadNotify.cs: close the pipe and detach the GSource when explicitly requested or finalized. svn path=/trunk/gtk-sharp/; revision=19142 --- ChangeLog | 5 +++++ gtk/ThreadNotify.cs | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e7088007..578478a3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-10-17 Gonzalo Paniagua Javier + + * gtk/ThreadNotify.cs: close the pipe and detach the GSource when + explicitly requested or finalized. + 2003-10-17 Gonzalo Paniagua Javier * gconf/tools/schemagen.cs: support for lists. diff --git a/gtk/ThreadNotify.cs b/gtk/ThreadNotify.cs index 9db6f201a..11c0a3b6d 100644 --- a/gtk/ThreadNotify.cs +++ b/gtk/ThreadNotify.cs @@ -23,13 +23,13 @@ namespace Gtk { /// /// /// - public class ThreadNotify { + public class ThreadNotify : IDisposable { // // DllImport functions from Gtk // [DllImport ("libgtk-win32-2.0-0.dll")] - private static extern int gdk_input_add (int s, int cond, GdkInputFunction f, IntPtr data); + private static extern uint gdk_input_add (int s, int cond, GdkInputFunction f, IntPtr data); public delegate void GdkInputFunction (IntPtr data, int source, int cond); // @@ -44,9 +44,13 @@ namespace Gtk { [DllImport ("libc.so.6")] private static extern unsafe int write (int fd, byte *b, int count); + [DllImport ("libc.so.6")] + private static extern int close (int fd); GdkInputFunction notify_pipe; int [] pipes; + bool disposed; + uint tag; ReadyEvent re; @@ -59,7 +63,7 @@ namespace Gtk { notify_pipe = new GdkInputFunction (NotifyPipe); pipes = new int [2]; pipe (pipes); - gdk_input_add (pipes [0], 1, notify_pipe, (IntPtr) 0); + tag = gdk_input_add (pipes [0], 1, notify_pipe, (IntPtr) 0); this.re = re; } @@ -96,5 +100,34 @@ namespace Gtk { } } } + + public void Close () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + ~ThreadNotify () + { + Dispose (false); + } + + void IDisposable.Dispose () + { + Close (); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposed) { + disposed = true; + GLib.Source.Remove (tag); + close (pipes [1]); + close (pipes [0]); + } + + pipes = null; + notify_pipe = null; + } } }