Merge remote branch 'gvdb/master'
[platform/upstream/glib.git] / gio / gcancellable.c
index db23575..3a99532 100644 (file)
@@ -24,6 +24,7 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#include <errno.h>
 #include <fcntl.h>
 #include <gioerror.h>
 #ifdef G_OS_WIN32
@@ -33,7 +34,6 @@
 #include "gcancellable.h"
 #include "glibintl.h"
 
-#include "gioalias.h"
 
 /**
  * SECTION:gcancellable
@@ -226,7 +226,6 @@ set_fd_close_exec (int fd)
 static void
 g_cancellable_open_pipe (GCancellable *cancellable)
 {
-  const char ch = 'x';
   GCancellablePrivate *priv;
 
   priv = cancellable->priv;
@@ -241,7 +240,14 @@ g_cancellable_open_pipe (GCancellable *cancellable)
       set_fd_close_exec (priv->cancel_pipe[1]);
       
       if (priv->cancelled)
-        write (priv->cancel_pipe[1], &ch, 1);
+        {
+          const char ch = 'x';
+          gssize c;
+
+          do
+            c = write (priv->cancel_pipe[1], &ch, 1);
+          while (c == -1 && errno == EINTR);
+        }
     }
 }
 #endif
@@ -327,7 +333,7 @@ g_cancellable_pop_current (GCancellable *cancellable)
  *
  * Gets the top cancellable from the stack.
  *
- * Returns: a #GCancellable from the top of the stack, or %NULL
+ * Returns: (transfer none): a #GCancellable from the top of the stack, or %NULL
  * if the stack is empty.
  **/
 GCancellable *
@@ -368,8 +374,6 @@ g_cancellable_reset (GCancellable *cancellable)
   
   if (priv->cancelled)
     {
-      char ch;
-      
     /* Make sure we're not leaving old cancel state around */
       
 #ifdef G_OS_WIN32
@@ -377,7 +381,15 @@ g_cancellable_reset (GCancellable *cancellable)
        ResetEvent (priv->event);
 #endif
       if (priv->cancel_pipe[0] != -1)
-       read (priv->cancel_pipe[0], &ch, 1);
+        {
+          gssize c;
+          char ch;
+
+          do
+            c = read (priv->cancel_pipe[0], &ch, 1);
+          while (c == -1 && errno == EINTR);
+        }
+
       priv->cancelled = FALSE;
     }
   G_UNLOCK(cancellable);
@@ -566,6 +578,9 @@ g_cancellable_release_fd (GCancellable *cancellable)
 {
   GCancellablePrivate *priv;
 
+  if (cancellable == NULL)
+    return;
+
   g_return_if_fail (G_IS_CANCELLABLE (cancellable));
   g_return_if_fail (cancellable->priv->fd_refcount > 0);
 
@@ -600,8 +615,6 @@ g_cancellable_release_fd (GCancellable *cancellable)
 void
 g_cancellable_cancel (GCancellable *cancellable)
 {
-  const char ch = 'x';
-  gboolean cancel;
   GCancellablePrivate *priv;
 
   if (cancellable == NULL ||
@@ -609,10 +622,14 @@ g_cancellable_cancel (GCancellable *cancellable)
     return;
 
   priv = cancellable->priv;
-  cancel = FALSE;
 
   G_LOCK(cancellable);
-  cancel = TRUE;
+  if (priv->cancelled)
+    {
+      G_UNLOCK (cancellable);
+      return;
+    }
+
   priv->cancelled = TRUE;
   priv->cancelled_running = TRUE;
 #ifdef G_OS_WIN32
@@ -620,25 +637,29 @@ g_cancellable_cancel (GCancellable *cancellable)
     SetEvent (priv->event);
 #endif
   if (priv->cancel_pipe[1] != -1)
-    write (priv->cancel_pipe[1], &ch, 1);
+    {
+      const char ch = 'x';
+      gssize c;
+
+      do
+        c = write (priv->cancel_pipe[1], &ch, 1);
+      while (c == -1 && errno == EINTR);
+    }
   G_UNLOCK(cancellable);
 
-  if (cancel)
-    {
-      g_object_ref (cancellable);
-      g_signal_emit (cancellable, signals[CANCELLED], 0);
+  g_object_ref (cancellable);
+  g_signal_emit (cancellable, signals[CANCELLED], 0);
 
-      G_LOCK(cancellable);
+  G_LOCK(cancellable);
 
-      priv->cancelled_running = FALSE;
-      if (priv->cancelled_running_waiting)
-       g_cond_broadcast (cancellable_cond);
-      priv->cancelled_running_waiting = FALSE;
+  priv->cancelled_running = FALSE;
+  if (priv->cancelled_running_waiting)
+    g_cond_broadcast (cancellable_cond);
+  priv->cancelled_running_waiting = FALSE;
 
-      G_UNLOCK(cancellable);
+  G_UNLOCK(cancellable);
 
-      g_object_unref (cancellable);
-    }
+  g_object_unref (cancellable);
 }
 
 /**
@@ -749,6 +770,3 @@ g_cancellable_disconnect (GCancellable  *cancellable,
   g_signal_handler_disconnect (cancellable, handler_id);
   G_UNLOCK (cancellable);
 }
-
-#define __G_CANCELLABLE_C__
-#include "gioaliasdef.c"