2004-03-06 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* 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
This commit is contained in:
parent
5d8e9c5dd3
commit
4dcdbb53fe
5 changed files with 26 additions and 122 deletions
|
@ -1,3 +1,12 @@
|
|||
2004-03-06 Gonzalo Paniagua Javier <gonzalo@ximian.com>
|
||||
|
||||
* 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 <gonzalo@ximian.com>
|
||||
|
||||
* glue/Makefile.am:
|
||||
|
|
|
@ -20,7 +20,6 @@ BASESOURCES = \
|
|||
selectiondata.c \
|
||||
slist.c \
|
||||
style.c \
|
||||
thread-notify.c \
|
||||
time_t.c \
|
||||
type.c \
|
||||
value.c \
|
||||
|
|
|
@ -22,7 +22,6 @@ GLUE_OBJS = \
|
|||
selectiondata.o \
|
||||
slist.o \
|
||||
style.o \
|
||||
thread-notify.o \
|
||||
time_t.o \
|
||||
type.o \
|
||||
value.o \
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
}
|
||||
|
|
@ -26,32 +26,10 @@ namespace Gtk {
|
|||
/// <remarks/>
|
||||
///
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// The ReadyEvent delegate will be invoked on the current thread (which should
|
||||
|
@ -59,45 +37,35 @@ namespace Gtk {
|
|||
/// </summary>
|
||||
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;
|
||||
lock (this) {
|
||||
if (disposed)
|
||||
return false;
|
||||
|
||||
unsafe {
|
||||
lock (this) {
|
||||
pipe_read (pipes [0], &s, 1);
|
||||
notified = false;
|
||||
}
|
||||
notified = false;
|
||||
}
|
||||
|
||||
re ();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool notified = false;
|
||||
|
||||
/// <summary>
|
||||
/// Invoke this function from a thread to call the `ReadyEvent'
|
||||
/// delegate provided in the constructor on the Main Gtk thread
|
||||
/// </summary>
|
||||
public void WakeupMain ()
|
||||
{
|
||||
unsafe {
|
||||
byte s;
|
||||
lock (this){
|
||||
if (notified)
|
||||
return;
|
||||
|
||||
lock (this){
|
||||
if (notified)
|
||||
return;
|
||||
|
||||
pipe_write (pipes [1], &s, 1);
|
||||
notified = true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue