[glib] [gio] minor improvements to g_cancellable_cancel()
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib] [gio] minor improvements to g_cancellable_cancel()
- Date: Sun, 5 Jul 2009 19:36:14 +0000 (UTC)
commit c85ff0c75004736d5c8798e3b47a47e0fc67ac70
Author: Benjamin Otte <otte gnome org>
Date: Sun Jul 5 21:34:39 2009 +0200
[gio] minor improvements to g_cancellable_cancel()
- make this function not crash when cancellable is NULL
- avoid locking when the cancellable has already been cancelled
gio/gcancellable.c | 24 ++++++++++++------------
1 files changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index 888032d..8654883 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -514,27 +514,27 @@ g_cancellable_make_pollfd (GCancellable *cancellable, GPollFD *pollfd)
void
g_cancellable_cancel (GCancellable *cancellable)
{
+ static const char ch = 'x';
gboolean cancel;
GCancellablePrivate *priv;
+ if (cancellable == NULL ||
+ priv->cancelled)
+ return;
+
priv = cancellable->priv;
cancel = FALSE;
G_LOCK(cancellable);
- if (cancellable != NULL &&
- !priv->cancelled)
- {
- char ch = 'x';
- cancel = TRUE;
- priv->cancelled = TRUE;
- priv->cancelled_running = TRUE;
+ cancel = TRUE;
+ priv->cancelled = TRUE;
+ priv->cancelled_running = TRUE;
#ifdef G_OS_WIN32
- if (priv->event)
- SetEvent(priv->event);
+ if (priv->event)
+ SetEvent(priv->event);
#endif
- if (priv->cancel_pipe[1] != -1)
- write (priv->cancel_pipe[1], &ch, 1);
- }
+ if (priv->cancel_pipe[1] != -1)
+ write (priv->cancel_pipe[1], &ch, 1);
G_UNLOCK(cancellable);
if (cancel)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]