diff --git a/ChangeLog b/ChangeLog index c3f3d8f42..7e3b3ba04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-03-04 Gonzalo Paniagua Javier + + * glue/Makefile.am: + * glue/makefile.win32: added thread-notify.o + + * glue/thread-notify.c: handles pipe creation/read/write/close for + ThreadNotify. + + * gtk/ThreadNotify.cs: P/Invoke the thread-notify code instead of libc + functions. + 2004-02-26 Mike Kestner * configure.in : tagged 0.17 and bumped cvs version. diff --git a/glue/Makefile.am b/glue/Makefile.am index d9ba2fa93..7bc2b5226 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -20,6 +20,7 @@ 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 9550fe028..3e0b050b3 100755 --- a/glue/makefile.win32 +++ b/glue/makefile.win32 @@ -22,6 +22,7 @@ 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 new file mode 100755 index 000000000..ac82b5c16 --- /dev/null +++ b/glue/thread-notify.c @@ -0,0 +1,66 @@ +/* + * 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 11c0a3b6d..12ecf5b1d 100644 --- a/gtk/ThreadNotify.cs +++ b/gtk/ThreadNotify.cs @@ -2,10 +2,12 @@ // ThreadNotify.cs: implements a notification for the thread running the Gtk main // loop from another thread // -// Author: +// Authors: // Miguel de Icaza (miguel@ximian.com). +// Gonzalo Paniagua Javier (gonzalo@ximian.com) // // (C) 2002 Ximian, Inc. +// (C) 2004 Novell, Inc. // namespace Gtk { @@ -29,24 +31,21 @@ namespace Gtk { // DllImport functions from Gtk // [DllImport ("libgtk-win32-2.0-0.dll")] - private static extern uint gdk_input_add (int s, int cond, GdkInputFunction f, IntPtr data); + static extern uint gdk_input_add (int s, int cond, GdkInputFunction f, IntPtr data); public delegate void GdkInputFunction (IntPtr data, int source, int cond); - // - // Libc stuff - // - [DllImport ("libc.so.6")] - private static extern int pipe (int [] fd); + [DllImport ("gtksharpglue")] + static extern int pipe_create (int [] fd); - [DllImport ("libc.so.6")] - private static extern unsafe int read (int fd, byte *b, int count); + [DllImport ("gtksharpglue")] + static extern unsafe int pipe_read (int fd, byte *b, int count); - [DllImport ("libc.so.6")] - private static extern unsafe int write (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); - [DllImport ("libc.so.6")] - private static extern int close (int fd); - GdkInputFunction notify_pipe; int [] pipes; bool disposed; @@ -62,7 +61,7 @@ namespace Gtk { { notify_pipe = new GdkInputFunction (NotifyPipe); pipes = new int [2]; - pipe (pipes); + pipe_create (pipes); tag = gdk_input_add (pipes [0], 1, notify_pipe, (IntPtr) 0); this.re = re; } @@ -73,7 +72,7 @@ namespace Gtk { unsafe { lock (this) { - read (pipes [0], &s, 1); + pipe_read (pipes [0], &s, 1); notified = false; } } @@ -95,7 +94,8 @@ namespace Gtk { lock (this){ if (notified) return; - write (pipes [1], &s, 1); + + pipe_write (pipes [1], &s, 1); notified = true; } } @@ -122,8 +122,7 @@ namespace Gtk { if (!disposed) { disposed = true; GLib.Source.Remove (tag); - close (pipes [1]); - close (pipes [0]); + pipe_close (pipes); } pipes = null; @@ -131,3 +130,4 @@ namespace Gtk { } } } +