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>
|
2004-03-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
|
||||||
|
|
||||||
* glue/Makefile.am:
|
* glue/Makefile.am:
|
||||||
|
|
|
@ -20,7 +20,6 @@ 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,7 +22,6 @@ 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 \
|
||||||
|
|
|
@ -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/>
|
/// <remarks/>
|
||||||
///
|
///
|
||||||
public class ThreadNotify : IDisposable {
|
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;
|
bool disposed;
|
||||||
uint tag;
|
|
||||||
|
|
||||||
ReadyEvent re;
|
ReadyEvent re;
|
||||||
|
GLib.IdleHandler idle;
|
||||||
|
bool notified;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ReadyEvent delegate will be invoked on the current thread (which should
|
/// The ReadyEvent delegate will be invoked on the current thread (which should
|
||||||
|
@ -59,45 +37,35 @@ namespace Gtk {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ThreadNotify (ReadyEvent re)
|
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;
|
this.re = re;
|
||||||
|
idle = new GLib.IdleHandler (CallbackWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyPipe (IntPtr data, int source, int cond)
|
bool CallbackWrapper ()
|
||||||
{
|
{
|
||||||
byte s;
|
lock (this) {
|
||||||
|
if (disposed)
|
||||||
unsafe {
|
return false;
|
||||||
lock (this) {
|
|
||||||
pipe_read (pipes [0], &s, 1);
|
notified = false;
|
||||||
notified = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
re ();
|
re ();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notified = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoke this function from a thread to call the `ReadyEvent'
|
/// Invoke this function from a thread to call the `ReadyEvent'
|
||||||
/// delegate provided in the constructor on the Main Gtk thread
|
/// delegate provided in the constructor on the Main Gtk thread
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void WakeupMain ()
|
public void WakeupMain ()
|
||||||
{
|
{
|
||||||
unsafe {
|
lock (this){
|
||||||
byte s;
|
if (notified)
|
||||||
|
return;
|
||||||
lock (this){
|
|
||||||
if (notified)
|
notified = true;
|
||||||
return;
|
GLib.Idle.Add (idle);
|
||||||
|
|
||||||
pipe_write (pipes [1], &s, 1);
|
|
||||||
notified = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,14 +87,9 @@ namespace Gtk {
|
||||||
|
|
||||||
protected virtual void Dispose (bool disposing)
|
protected virtual void Dispose (bool disposing)
|
||||||
{
|
{
|
||||||
if (!disposed) {
|
lock (this) {
|
||||||
disposed = true;
|
disposed = true;
|
||||||
GLib.Source.Remove (tag);
|
|
||||||
pipe_close (pipes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pipes = null;
|
|
||||||
notify_pipe = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue