From 90381ecdbd73197ebdfaf58fdeccf267454d53d7 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 19 Jun 2009 10:30:14 -0400 Subject: [PATCH] Use low-level GSource methods in a few more places (in preparation for thread-default context support) --- gio/gfilemonitor.c | 23 ++++++++++++++--------- gio/gunixmount.c | 26 ++++++++++++++++++++++---- gio/gunixvolume.c | 26 ++++++++++++++++++++++---- gio/gwin32resolver.c | 18 ++++++++++++------ gio/pltcheck.sh | 2 +- 5 files changed, 71 insertions(+), 24 deletions(-) diff --git a/gio/gfilemonitor.c b/gio/gfilemonitor.c index 41444e3..b24a466 100644 --- a/gio/gfilemonitor.c +++ b/gio/gfilemonitor.c @@ -77,7 +77,7 @@ struct _GFileMonitorPrivate { /* Rate limiting change events */ GHashTable *rate_limiter; - guint pending_file_change_id; + GSource *pending_file_change_source; GSList *pending_file_changes; /* FileChange */ GSource *timeout; @@ -181,10 +181,11 @@ g_file_monitor_dispose (GObject *object) monitor = G_FILE_MONITOR (object); priv = monitor->priv; - if (priv->pending_file_change_id) + if (priv->pending_file_change_source) { - g_source_remove (priv->pending_file_change_id); - priv->pending_file_change_id = 0; + g_source_destroy (priv->pending_file_change_source); + g_source_unref (priv->pending_file_change_source); + priv->pending_file_change_source = NULL; } g_slist_foreach (priv->pending_file_changes, (GFunc) file_change_free, NULL); g_slist_free (priv->pending_file_changes); @@ -362,7 +363,11 @@ emit_cb (gpointer data) pending = g_slist_reverse (monitor->priv->pending_file_changes); monitor->priv->pending_file_changes = NULL; - monitor->priv->pending_file_change_id = 0; + if (monitor->priv->pending_file_change_source) + { + g_source_unref (monitor->priv->pending_file_change_source); + monitor->priv->pending_file_change_source = NULL; + } g_object_ref (monitor); for (iter = pending; iter; iter = iter->next) @@ -399,17 +404,17 @@ emit_in_idle (GFileMonitor *monitor, change->other_file = NULL; change->event_type = event_type; - if (!priv->pending_file_change_id) + if (!priv->pending_file_change_source) { source = g_idle_source_new (); + priv->pending_file_change_source = source; g_source_set_priority (source, 0); - /* We don't ref here - instead dispose will free any + /* We don't ref monitor here - instead dispose will free any * pending idles. */ g_source_set_callback (source, emit_cb, monitor, NULL); - priv->pending_file_change_id = g_source_attach (source, NULL); - g_source_unref (source); + g_source_attach (source, NULL); } /* We reverse this in the processor */ priv->pending_file_changes = g_slist_prepend (priv->pending_file_changes, change); diff --git a/gio/gunixmount.c b/gio/gunixmount.c index 406c0ce..8856201 100644 --- a/gio/gunixmount.c +++ b/gio/gunixmount.c @@ -240,7 +240,7 @@ typedef struct { GCancellable *cancellable; int error_fd; GIOChannel *error_channel; - guint error_channel_source_id; + GSource *error_channel_source; GString *error_string; gchar **argv; } UnmountEjectOp; @@ -274,7 +274,11 @@ eject_unmount_cb (GPid pid, gint status, gpointer user_data) g_simple_async_result_complete (simple); g_object_unref (simple); - g_source_remove (data->error_channel_source_id); + if (data->error_channel_source) + { + g_source_destroy (data->error_channel_source); + g_source_unref (data->error_channel_source); + } g_io_channel_unref (data->error_channel); g_string_free (data->error_string, TRUE); g_strfreev (data->argv); @@ -312,6 +316,12 @@ read: g_string_append (data->error_string, error->message); g_error_free (error); + + if (data->error_channel_source) + { + g_source_unref (data->error_channel_source); + data->error_channel_source = NULL; + } return FALSE; } @@ -323,6 +333,7 @@ eject_unmount_do_cb (gpointer user_data) { UnmountEjectOp *data = (UnmountEjectOp *) user_data; GPid child_pid; + GSource *child_watch; GError *error = NULL; if (!g_spawn_async_with_pipes (NULL, /* working dir */ @@ -347,8 +358,15 @@ eject_unmount_do_cb (gpointer user_data) if (error != NULL) goto handle_error; - data->error_channel_source_id = g_io_add_watch (data->error_channel, G_IO_IN, eject_unmount_read_error, data); - g_child_watch_add (child_pid, eject_unmount_cb, data); + data->error_channel_source = g_io_create_watch (data->error_channel, G_IO_IN); + g_source_set_callback (data->error_channel_source, + (GSourceFunc) eject_unmount_read_error, data, NULL); + g_source_attach (data->error_channel_source, NULL); + + child_watch = g_child_watch_source_new (child_pid); + g_source_set_callback (child_watch, (GSourceFunc) eject_unmount_cb, data, NULL); + g_source_attach (child_watch, NULL); + g_source_unref (child_watch); handle_error: if (error != NULL) { diff --git a/gio/gunixvolume.c b/gio/gunixvolume.c index 91cb346..a1037ab 100644 --- a/gio/gunixvolume.c +++ b/gio/gunixvolume.c @@ -289,7 +289,7 @@ typedef struct { GCancellable *cancellable; int error_fd; GIOChannel *error_channel; - guint error_channel_source_id; + GSource *error_channel_source; GString *error_string; } EjectMountOp; @@ -322,7 +322,11 @@ eject_mount_cb (GPid pid, gint status, gpointer user_data) g_simple_async_result_complete (simple); g_object_unref (simple); - g_source_remove (data->error_channel_source_id); + if (data->error_channel_source) + { + g_source_destroy (data->error_channel_source); + g_source_unref (data->error_channel_source); + } g_io_channel_unref (data->error_channel); g_string_free (data->error_string, TRUE); close (data->error_fd); @@ -359,6 +363,12 @@ read: g_string_append (data->error_string, error->message); g_error_free (error); + + if (data->error_channel_source) + { + g_source_unref (data->error_channel_source); + data->error_channel_source = NULL; + } return FALSE; } @@ -375,6 +385,7 @@ eject_mount_do (GVolume *volume, GUnixVolume *unix_volume = G_UNIX_VOLUME (volume); EjectMountOp *data; GPid child_pid; + GSource *child_watch; GError *error; data = g_new0 (EjectMountOp, 1); @@ -406,8 +417,15 @@ eject_mount_do (GVolume *volume, if (error != NULL) goto handle_error; - data->error_channel_source_id = g_io_add_watch (data->error_channel, G_IO_IN, eject_mount_read_error, data); - g_child_watch_add (child_pid, eject_mount_cb, data); + data->error_channel_source = g_io_create_watch (data->error_channel, G_IO_IN); + g_source_set_callback (data->error_channel_source, + (GSourceFunc) eject_mount_read_error, data, NULL); + g_source_attach (data->error_channel_source, NULL); + + child_watch = g_child_watch_source_new (child_pid); + g_source_set_callback (child_watch, (GSourceFunc) eject_mount_cb, data, NULL); + g_source_attach (child_watch, NULL); + g_source_unref (child_watch); handle_error: if (error != NULL) { diff --git a/gio/gwin32resolver.c b/gio/gwin32resolver.c index cab45cc..b02b08c 100644 --- a/gio/gwin32resolver.c +++ b/gio/gwin32resolver.c @@ -95,7 +95,7 @@ struct GWin32ResolverRequest { HANDLE *event; GSimpleAsyncResult *async_result; gboolean complete; - guint cancelled_idle; + GSource *cancelled_idle; union { struct { @@ -167,8 +167,9 @@ request_completed (gpointer user_data) /* Clean up cancellation-related stuff first */ if (req->cancelled_idle) { - g_source_remove (req->cancelled_idle); - req->cancelled_idle = 0; + g_source_destroy (req->cancelled_idle); + g_source_unref (req->cancelled_idle); + req->cancelled_idle = NULL; } if (req->cancellable) { @@ -197,7 +198,8 @@ request_cancelled_idle (gpointer user_data) GWin32ResolverRequest *req = user_data; GError *error = NULL; - req->cancelled_idle = 0; + g_source_unref (req->cancelled_idle); + req->cancelled_idle = NULL; g_cancellable_set_error_if_cancelled (req->cancellable, &error); g_simple_async_result_set_from_error (req->async_result, error); @@ -226,9 +228,13 @@ request_cancelled (GCancellable *cancellable, /* We need to wait until main-loop-time to actually complete the * result; we don't use _complete_in_idle() here because we need to - * keep track of the source id. + * keep track of the source so we can potentially cancel it before + * it runs. */ - req->cancelled_idle = g_idle_add (request_cancelled_idle, req); + req->cancelled_idle = g_idle_source_new (); + g_source_set_callback (req->cancelled_idle, + (GSourceFunc)request_cancelled_idle, req, NULL); + g_source_attach (req->cancelled_idle, NULL); } static DWORD WINAPI diff --git a/gio/pltcheck.sh b/gio/pltcheck.sh index e159318..228ede9 100755 --- a/gio/pltcheck.sh +++ b/gio/pltcheck.sh @@ -9,7 +9,7 @@ if ! which readelf 2>/dev/null >/dev/null; then exit 0 fi -SKIP='\