2004-03-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* 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.

svn path=/trunk/gtk-sharp/; revision=23734
This commit is contained in:
Gonzalo Paniagua Javier 2004-03-05 04:20:09 +00:00
parent cb2e88b1a7
commit dea79f5902
5 changed files with 98 additions and 19 deletions

View File

@ -1,3 +1,14 @@
2004-03-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* 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 <mkestner@ximian.com>
* configure.in : tagged 0.17 and bumped cvs version.

View File

@ -20,6 +20,7 @@ BASESOURCES = \
selectiondata.c \
slist.c \
style.c \
thread-notify.c \
time_t.c \
type.c \
value.c \

View File

@ -22,6 +22,7 @@ GLUE_OBJS = \
selectiondata.o \
slist.o \
style.o \
thread-notify.o \
time_t.o \
type.o \
value.o \

66
glue/thread-notify.c Executable file
View File

@ -0,0 +1,66 @@
/*
* Pipe for ThreadNotify
*
* (C) 2004 Gonzalo Paniagua Javier (gonzalo@ximian.com)
*/
#include <glib.h>
#ifdef G_OS_WIN32
#include <windows.h>
#else
#include <stdio.h>
#include <unistd.h>
#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
}

View File

@ -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 {
}
}
}