From 4dcdbb53fe7a0b62f70b30d0cd4d4be4ef834e0b Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Sat, 6 Mar 2004 18:48:20 +0000 Subject: [PATCH] 2004-03-06 Gonzalo Paniagua Javier * glue/Makefile.am: * glue/makefile.win32: * glue/thread-notify.c: dropped. * gtk/ThreadNotify.cs: use just Idle.Add, which is what the deprecated gda_input_add does. No more P/Invoke here. svn path=/trunk/gtk-sharp/; revision=23758 --- ChangeLog | 9 ++++++ glue/Makefile.am | 1 - glue/makefile.win32 | 1 - glue/thread-notify.c | 66 ---------------------------------------- gtk/ThreadNotify.cs | 71 +++++++++++--------------------------------- 5 files changed, 26 insertions(+), 122 deletions(-) delete mode 100755 glue/thread-notify.c diff --git a/ChangeLog b/ChangeLog index 7e3b3ba04..13f4eaf2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-03-06 Gonzalo Paniagua Javier + + * glue/Makefile.am: + * glue/makefile.win32: + * glue/thread-notify.c: dropped. + + * gtk/ThreadNotify.cs: use just Idle.Add, which is what the deprecated + gda_input_add does. No more P/Invoke here. + 2004-03-04 Gonzalo Paniagua Javier * glue/Makefile.am: diff --git a/glue/Makefile.am b/glue/Makefile.am index 7bc2b5226..d9ba2fa93 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -20,7 +20,6 @@ BASESOURCES = \ selectiondata.c \ slist.c \ style.c \ - thread-notify.c \ time_t.c \ type.c \ value.c \ diff --git a/glue/makefile.win32 b/glue/makefile.win32 index 3e0b050b3..9550fe028 100755 --- a/glue/makefile.win32 +++ b/glue/makefile.win32 @@ -22,7 +22,6 @@ GLUE_OBJS = \ selectiondata.o \ slist.o \ style.o \ - thread-notify.o \ time_t.o \ type.o \ value.o \ diff --git a/glue/thread-notify.c b/glue/thread-notify.c deleted file mode 100755 index ac82b5c16..000000000 --- a/glue/thread-notify.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Pipe for ThreadNotify - * - * (C) 2004 Gonzalo Paniagua Javier (gonzalo@ximian.com) - */ - -#include -#ifdef G_OS_WIN32 -#include -#else -#include -#include -#endif - -gint pipe_create (gint *fds); - -gint -pipe_create (gint *fds) -{ -#ifdef G_OS_WIN32 - return !CreatePipe ((PHANDLE) fds, (PHANDLE) &fds [1], NULL, 1024); -#else - return pipe (fds); -#endif -} - -gint pipe_read (gint fd, gchar *buffer, gint maxcount); - -gint -pipe_read (gint fd, gchar *buffer, gint maxcount) -{ -#ifdef G_OS_WIN32 - glong dummy; - return !ReadFile ((HANDLE) fd, buffer, maxcount, &dummy, NULL); -#else - return (read (fd, buffer, maxcount) < 0); -#endif -} - -gint pipe_write (gint fd, gchar *buffer, gint maxcount); - -gint -pipe_write (gint fd, gchar *buffer, gint maxcount) -{ -#ifdef G_OS_WIN32 - glong dummy; - return !WriteFile ((HANDLE) fd, buffer, maxcount, &dummy, NULL); -#else - return (write (fd, buffer, maxcount) < 0); -#endif -} - -void pipe_close (gint *fds); - -void -pipe_close (gint *fds) -{ -#ifdef G_OS_WIN32 - CloseHandle ((HANDLE) fds [0]); - CloseHandle ((HANDLE) fds [1]); -#else - close (fds [0]); - close (fds [1]); -#endif -} - diff --git a/gtk/ThreadNotify.cs b/gtk/ThreadNotify.cs index 12ecf5b1d..e72fbdd20 100644 --- a/gtk/ThreadNotify.cs +++ b/gtk/ThreadNotify.cs @@ -26,32 +26,10 @@ namespace Gtk { /// /// public class ThreadNotify : IDisposable { - - // - // DllImport functions from Gtk - // - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern uint gdk_input_add (int s, int cond, GdkInputFunction f, IntPtr data); - public delegate void GdkInputFunction (IntPtr data, int source, int cond); - - [DllImport ("gtksharpglue")] - static extern int pipe_create (int [] fd); - - [DllImport ("gtksharpglue")] - static extern unsafe int pipe_read (int fd, byte *b, int count); - - [DllImport ("gtksharpglue")] - static extern unsafe int pipe_write (int fd, byte *b, int count); - - [DllImport ("gtksharpglue")] - static extern int pipe_close (int [] fd); - - GdkInputFunction notify_pipe; - int [] pipes; bool disposed; - uint tag; - ReadyEvent re; + GLib.IdleHandler idle; + bool notified; /// /// The ReadyEvent delegate will be invoked on the current thread (which should @@ -59,45 +37,35 @@ namespace Gtk { /// public ThreadNotify (ReadyEvent re) { - notify_pipe = new GdkInputFunction (NotifyPipe); - pipes = new int [2]; - pipe_create (pipes); - tag = gdk_input_add (pipes [0], 1, notify_pipe, (IntPtr) 0); this.re = re; + idle = new GLib.IdleHandler (CallbackWrapper); } - void NotifyPipe (IntPtr data, int source, int cond) + bool CallbackWrapper () { - byte s; - - unsafe { - lock (this) { - pipe_read (pipes [0], &s, 1); - notified = false; - } + lock (this) { + if (disposed) + return false; + + notified = false; } re (); + return false; } - bool notified = false; - /// /// Invoke this function from a thread to call the `ReadyEvent' /// delegate provided in the constructor on the Main Gtk thread /// public void WakeupMain () { - unsafe { - byte s; - - lock (this){ - if (notified) - return; - - pipe_write (pipes [1], &s, 1); - notified = true; - } + lock (this){ + if (notified) + return; + + notified = true; + GLib.Idle.Add (idle); } } @@ -119,14 +87,9 @@ namespace Gtk { protected virtual void Dispose (bool disposing) { - if (!disposed) { + lock (this) { disposed = true; - GLib.Source.Remove (tag); - pipe_close (pipes); } - - pipes = null; - notify_pipe = null; } } }