summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-06-01 15:23:15 -0300
committerDan Winship <danw@gnome.org>2013-07-13 16:38:55 -0400
commit8a899265329f6bbbb066991fdc036045d7031b37 (patch)
treebac2c8aacae46cdbd3bed32ff963aa9304a10262
parent1da47d5ede3384105c035638fb4eb533d8989e20 (diff)
downloadglib-8a899265329f6bbbb066991fdc036045d7031b37.tar.gz
gsourceclosure: Add support for GUnixSignalWatchSource and GUnixFDSource
https://bugzilla.gnome.org/show_bug.cgi?id=701511
-rw-r--r--glib/glib-unix.c8
-rw-r--r--glib/gmain.c2
-rw-r--r--glib/gmain.h4
-rw-r--r--gobject/gsourceclosure.c45
4 files changed, 54 insertions, 5 deletions
diff --git a/glib/glib-unix.c b/glib/glib-unix.c
index b1cade478..8f1fe1cc1 100644
--- a/glib/glib-unix.c
+++ b/glib/glib-unix.c
@@ -315,6 +315,9 @@ g_unix_fd_source_dispatch (GSource *source,
return (* func) (fd_source->fd, g_source_query_unix_fd (source, fd_source->tag), user_data);
}
+GSourceFuncs g_unix_fd_source_funcs = {
+ NULL, NULL, g_unix_fd_source_dispatch, NULL
+};
/**
* g_unix_fd_source_new:
@@ -334,13 +337,10 @@ GSource *
g_unix_fd_source_new (gint fd,
GIOCondition condition)
{
- static GSourceFuncs source_funcs = {
- NULL, NULL, g_unix_fd_source_dispatch, NULL
- };
GUnixFDSource *fd_source;
GSource *source;
- source = g_source_new (&source_funcs, sizeof (GUnixFDSource));
+ source = g_source_new (&g_unix_fd_source_funcs, sizeof (GUnixFDSource));
fd_source = (GUnixFDSource *) source;
fd_source->fd = fd;
diff --git a/glib/gmain.c b/glib/gmain.c
index 3c6610855..7f1d2b98b 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -434,7 +434,7 @@ G_LOCK_DEFINE_STATIC (unix_signal_lock);
static GSList *unix_signal_watches;
static GSList *unix_child_watches;
-static GSourceFuncs g_unix_signal_funcs =
+GSourceFuncs g_unix_signal_funcs =
{
g_unix_signal_watch_prepare,
g_unix_signal_watch_check,
diff --git a/glib/gmain.h b/glib/gmain.h
index 47b4ecf1f..d6370fa44 100644
--- a/glib/gmain.h
+++ b/glib/gmain.h
@@ -605,6 +605,10 @@ void g_main_context_invoke (GMainContext *context,
GLIB_VAR GSourceFuncs g_timeout_funcs;
GLIB_VAR GSourceFuncs g_child_watch_funcs;
GLIB_VAR GSourceFuncs g_idle_funcs;
+#ifdef G_OS_UNIX
+GLIB_VAR GSourceFuncs g_unix_signal_funcs;
+GLIB_VAR GSourceFuncs g_unix_fd_source_funcs;
+#endif
G_END_DECLS
diff --git a/gobject/gsourceclosure.c b/gobject/gsourceclosure.c
index f5425f215..26b89529f 100644
--- a/gobject/gsourceclosure.c
+++ b/gobject/gsourceclosure.c
@@ -25,6 +25,9 @@
#include "gmarshal.h"
#include "gvalue.h"
#include "gvaluetypes.h"
+#ifdef G_OS_UNIX
+#include "glib-unix.h"
+#endif
G_DEFINE_BOXED_TYPE (GIOChannel, g_io_channel, g_io_channel_ref, g_io_channel_unref)
@@ -76,6 +79,37 @@ io_watch_closure_callback (GIOChannel *channel,
return result;
}
+#ifdef G_OS_UNIX
+static gboolean
+g_unix_fd_source_closure_callback (int fd,
+ GIOCondition condition,
+ gpointer data)
+{
+ GClosure *closure = data;
+
+ GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
+ GValue result_value = G_VALUE_INIT;
+ gboolean result;
+
+ g_value_init (&result_value, G_TYPE_BOOLEAN);
+
+ g_value_init (&params[0], G_TYPE_INT);
+ g_value_set_int (&params[0], fd);
+
+ g_value_init (&params[1], G_TYPE_IO_CONDITION);
+ g_value_set_flags (&params[1], condition);
+
+ g_closure_invoke (closure, &result_value, 2, params, NULL);
+
+ result = g_value_get_boolean (&result_value);
+ g_value_unset (&result_value);
+ g_value_unset (&params[0]);
+ g_value_unset (&params[1]);
+
+ return result;
+}
+#endif
+
static gboolean
source_closure_callback (gpointer data)
{
@@ -105,7 +139,14 @@ closure_callback_get (gpointer cb_data,
{
if (source->source_funcs == &g_io_watch_funcs)
closure_callback = (GSourceFunc)io_watch_closure_callback;
+#ifdef G_OS_UNIX
+ else if (source->source_funcs == &g_unix_fd_source_funcs)
+ closure_callback = (GSourceFunc)g_unix_fd_source_closure_callback;
+#endif
else if (source->source_funcs == &g_timeout_funcs ||
+#ifdef G_OS_UNIX
+ source->source_funcs == &g_unix_signal_funcs ||
+#endif
source->source_funcs == &g_idle_funcs)
closure_callback = source_closure_callback;
}
@@ -146,6 +187,10 @@ g_source_set_closure (GSource *source,
g_return_if_fail (closure != NULL);
if (!source->source_funcs->closure_callback &&
+#ifdef G_OS_UNIX
+ source->source_funcs != &g_unix_fd_source_funcs &&
+ source->source_funcs != &g_unix_signal_funcs &&
+#endif
source->source_funcs != &g_io_watch_funcs &&
source->source_funcs != &g_timeout_funcs &&
source->source_funcs != &g_idle_funcs)