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:
parent
cb2e88b1a7
commit
dea79f5902
5 changed files with 98 additions and 19 deletions
11
ChangeLog
11
ChangeLog
|
@ -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>
|
2004-02-26 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* configure.in : tagged 0.17 and bumped cvs version.
|
* configure.in : tagged 0.17 and bumped cvs version.
|
||||||
|
|
|
@ -20,6 +20,7 @@ BASESOURCES = \
|
||||||
selectiondata.c \
|
selectiondata.c \
|
||||||
slist.c \
|
slist.c \
|
||||||
style.c \
|
style.c \
|
||||||
|
thread-notify.c \
|
||||||
time_t.c \
|
time_t.c \
|
||||||
type.c \
|
type.c \
|
||||||
value.c \
|
value.c \
|
||||||
|
|
|
@ -22,6 +22,7 @@ GLUE_OBJS = \
|
||||||
selectiondata.o \
|
selectiondata.o \
|
||||||
slist.o \
|
slist.o \
|
||||||
style.o \
|
style.o \
|
||||||
|
thread-notify.o \
|
||||||
time_t.o \
|
time_t.o \
|
||||||
type.o \
|
type.o \
|
||||||
value.o \
|
value.o \
|
||||||
|
|
66
glue/thread-notify.c
Executable file
66
glue/thread-notify.c
Executable 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
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
// ThreadNotify.cs: implements a notification for the thread running the Gtk main
|
// ThreadNotify.cs: implements a notification for the thread running the Gtk main
|
||||||
// loop from another thread
|
// loop from another thread
|
||||||
//
|
//
|
||||||
// Author:
|
// Authors:
|
||||||
// Miguel de Icaza (miguel@ximian.com).
|
// Miguel de Icaza (miguel@ximian.com).
|
||||||
|
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
|
||||||
//
|
//
|
||||||
// (C) 2002 Ximian, Inc.
|
// (C) 2002 Ximian, Inc.
|
||||||
|
// (C) 2004 Novell, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
namespace Gtk {
|
namespace Gtk {
|
||||||
|
@ -29,23 +31,20 @@ namespace Gtk {
|
||||||
// DllImport functions from Gtk
|
// DllImport functions from Gtk
|
||||||
//
|
//
|
||||||
[DllImport ("libgtk-win32-2.0-0.dll")]
|
[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);
|
public delegate void GdkInputFunction (IntPtr data, int source, int cond);
|
||||||
|
|
||||||
//
|
[DllImport ("gtksharpglue")]
|
||||||
// Libc stuff
|
static extern int pipe_create (int [] fd);
|
||||||
//
|
|
||||||
[DllImport ("libc.so.6")]
|
|
||||||
private static extern int pipe (int [] fd);
|
|
||||||
|
|
||||||
[DllImport ("libc.so.6")]
|
[DllImport ("gtksharpglue")]
|
||||||
private static extern unsafe int read (int fd, byte *b, int count);
|
static extern unsafe int pipe_read (int fd, byte *b, int count);
|
||||||
|
|
||||||
[DllImport ("libc.so.6")]
|
[DllImport ("gtksharpglue")]
|
||||||
private static extern unsafe int write (int fd, byte *b, int count);
|
static extern unsafe int pipe_write (int fd, byte *b, int count);
|
||||||
|
|
||||||
[DllImport ("libc.so.6")]
|
[DllImport ("gtksharpglue")]
|
||||||
private static extern int close (int fd);
|
static extern int pipe_close (int [] fd);
|
||||||
|
|
||||||
GdkInputFunction notify_pipe;
|
GdkInputFunction notify_pipe;
|
||||||
int [] pipes;
|
int [] pipes;
|
||||||
|
@ -62,7 +61,7 @@ namespace Gtk {
|
||||||
{
|
{
|
||||||
notify_pipe = new GdkInputFunction (NotifyPipe);
|
notify_pipe = new GdkInputFunction (NotifyPipe);
|
||||||
pipes = new int [2];
|
pipes = new int [2];
|
||||||
pipe (pipes);
|
pipe_create (pipes);
|
||||||
tag = gdk_input_add (pipes [0], 1, notify_pipe, (IntPtr) 0);
|
tag = gdk_input_add (pipes [0], 1, notify_pipe, (IntPtr) 0);
|
||||||
this.re = re;
|
this.re = re;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ namespace Gtk {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
lock (this) {
|
lock (this) {
|
||||||
read (pipes [0], &s, 1);
|
pipe_read (pipes [0], &s, 1);
|
||||||
notified = false;
|
notified = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +94,8 @@ namespace Gtk {
|
||||||
lock (this){
|
lock (this){
|
||||||
if (notified)
|
if (notified)
|
||||||
return;
|
return;
|
||||||
write (pipes [1], &s, 1);
|
|
||||||
|
pipe_write (pipes [1], &s, 1);
|
||||||
notified = true;
|
notified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,7 @@ namespace Gtk {
|
||||||
if (!disposed) {
|
if (!disposed) {
|
||||||
disposed = true;
|
disposed = true;
|
||||||
GLib.Source.Remove (tag);
|
GLib.Source.Remove (tag);
|
||||||
close (pipes [1]);
|
pipe_close (pipes);
|
||||||
close (pipes [0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pipes = null;
|
pipes = null;
|
||||||
|
@ -131,3 +130,4 @@ namespace Gtk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue