diff options
author | Dan Winship <danw@gnome.org> | 2010-11-06 15:49:55 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2010-11-26 15:07:28 -0500 |
commit | 6181c7de36771d4d3bb55785912a934e078b16df (patch) | |
tree | d26b2f688a1c6002775a91b380a1ed1fa11fe2c5 /gio/gasynchelper.c | |
parent | d15cdbefecc235cfa431ee7de9c35af174bd1552 (diff) |
GCancellable: add g_cancellable_create_source()
g_cancellable_create_source() returns a GSource that triggers when its
corresponding GCancellable is cancelled. This can be used with
g_source_add_child_source() to add cancellability to a source.
Port gasynchelper's FDSource to use this rather than doing its own
cancellable handling, and also fix up its callback argument order to
be more normal.
https://bugzilla.gnome.org/show_bug.cgi?id=634239
Diffstat (limited to 'gio/gasynchelper.c')
-rw-r--r-- | gio/gasynchelper.c | 47 |
1 files changed, 10 insertions, 37 deletions
diff --git a/gio/gasynchelper.c b/gio/gasynchelper.c index 57590a1ec..fb3d266e3 100644 --- a/gio/gasynchelper.c +++ b/gio/gasynchelper.c @@ -43,18 +43,14 @@ typedef struct { GSource source; GPollFD pollfd; - GCancellable *cancellable; - gulong cancelled_tag; } FDSource; static gboolean fd_source_prepare (GSource *source, gint *timeout) { - FDSource *fd_source = (FDSource *)source; *timeout = -1; - - return g_cancellable_is_cancelled (fd_source->cancellable); + return FALSE; } static gboolean @@ -62,9 +58,7 @@ fd_source_check (GSource *source) { FDSource *fd_source = (FDSource *)source; - return - g_cancellable_is_cancelled (fd_source->cancellable) || - fd_source->pollfd.revents != 0; + return fd_source->pollfd.revents != 0; } static gboolean @@ -84,18 +78,6 @@ fd_source_dispatch (GSource *source, static void fd_source_finalize (GSource *source) { - FDSource *fd_source = (FDSource *)source; - - /* we don't use g_cancellable_disconnect() here, since we are holding - * the main context lock here, and the ::disconnect signal handler - * will try to grab that, and deadlock looms. - */ - if (fd_source->cancelled_tag) - g_signal_handler_disconnect (fd_source->cancellable, - fd_source->cancelled_tag); - - if (fd_source->cancellable) - g_object_unref (fd_source->cancellable); } static gboolean @@ -160,15 +142,6 @@ static GSourceFuncs fd_source_funcs = { (GSourceDummyMarshal)fd_source_closure_marshal, }; -/* Might be called on another thread */ -static void -fd_source_cancelled_cb (GCancellable *cancellable, - gpointer data) -{ - /* Wake up the mainloop in case we're waiting on async calls with FDSource */ - g_main_context_wakeup (NULL); -} - GSource * _g_fd_source_new (int fd, gushort events, @@ -180,18 +153,18 @@ _g_fd_source_new (int fd, source = g_source_new (&fd_source_funcs, sizeof (FDSource)); fd_source = (FDSource *)source; - if (cancellable) - fd_source->cancellable = g_object_ref (cancellable); - fd_source->pollfd.fd = fd; fd_source->pollfd.events = events; g_source_add_poll (source, &fd_source->pollfd); if (cancellable) - fd_source->cancelled_tag = - g_cancellable_connect (cancellable, - (GCallback)fd_source_cancelled_cb, - NULL, NULL); - + { + GSource *cancellable_source = g_cancellable_source_new (cancellable); + + g_source_set_dummy_callback (cancellable_source); + g_source_add_child_source (source, cancellable_source); + g_source_unref (cancellable_source); + } + return source; } |