Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gstreamer.git] / gst / gstpoll.c
index 76a7a30..fed594f 100644 (file)
@@ -57,6 +57,7 @@
 #endif
 
 #include "gst_private.h"
+#include "glib-compat-private.h"
 
 #include <sys/types.h>
 
@@ -154,8 +155,8 @@ static gboolean gst_poll_add_fd_unlocked (GstPoll * set, GstPollFD * fd);
 #define IS_FLUSHING(s)      (g_atomic_int_get(&(s)->flushing))
 #define SET_FLUSHING(s,val) (g_atomic_int_set(&(s)->flushing, (val)))
 
-#define INC_WAITING(s)      (g_atomic_int_exchange_and_add(&(s)->waiting, 1))
-#define DEC_WAITING(s)      (g_atomic_int_exchange_and_add(&(s)->waiting, -1))
+#define INC_WAITING(s)      (G_ATOMIC_INT_ADD(&(s)->waiting, 1))
+#define DEC_WAITING(s)      (G_ATOMIC_INT_ADD(&(s)->waiting, -1))
 #define GET_WAITING(s)      (g_atomic_int_get(&(s)->waiting))
 
 #define TEST_REBUILD(s)     (g_atomic_int_compare_and_exchange(&(s)->rebuild, 1, 0))
@@ -165,7 +166,7 @@ static gboolean gst_poll_add_fd_unlocked (GstPoll * set, GstPollFD * fd);
 #define WAKE_EVENT(s)       (write ((s)->control_write_fd.fd, "W", 1) == 1)
 #define RELEASE_EVENT(s)    (read ((s)->control_read_fd.fd, (s)->buf, 1) == 1)
 #else
-#define WAKE_EVENT(s)       (SetEvent ((s)->wakeup_event))
+#define WAKE_EVENT(s)       (SetEvent ((s)->wakeup_event), errno = GetLastError () == NO_ERROR ? 0 : EACCES, errno == 0 ? 1 : 0)
 #define RELEASE_EVENT(s)    (ResetEvent ((s)->wakeup_event))
 #endif
 
@@ -176,8 +177,9 @@ raise_wakeup (GstPoll * set)
 {
   gboolean result = TRUE;
 
-  if (g_atomic_int_exchange_and_add (&set->control_pending, 1) == 0) {
+  if (G_ATOMIC_INT_ADD (&set->control_pending, 1) == 0) {
     /* raise when nothing pending */
+    GST_LOG ("%p: raise", set);
     result = WAKE_EVENT (set);
   }
   return result;
@@ -192,6 +194,7 @@ release_wakeup (GstPoll * set)
   gboolean result = TRUE;
 
   if (g_atomic_int_dec_and_test (&set->control_pending)) {
+    GST_LOG ("%p: release", set);
     result = RELEASE_EVENT (set);
   }
   return result;
@@ -214,7 +217,7 @@ release_all_wakeup (GstPoll * set)
         break;
       else
         /* retry again until we read it successfully */
-        g_atomic_int_exchange_and_add (&set->control_pending, 1);
+        G_ATOMIC_INT_ADD (&set->control_pending, 1);
     }
   }
   return old;
@@ -529,7 +532,7 @@ gst_poll_collect_winsock_events (GstPoll * set)
 #endif
 
 /**
- * gst_poll_new:
+ * gst_poll_new: (skip)
  * @controllable: whether it should be possible to control a wait.
  *
  * Create a new file descriptor set. If @controllable, it
@@ -603,7 +606,7 @@ no_socket_pair:
 }
 
 /**
- * gst_poll_new_timer:
+ * gst_poll_new_timer: (skip)
  *
  * Create a new poll object that can be used for scheduling cancellable
  * timeouts.
@@ -1231,7 +1234,7 @@ gst_poll_wait (GstPoll * set, GstClockTime timeout)
   if (G_UNLIKELY (old_waiting > 0 && !is_timer))
     goto already_waiting;
 
-  /* flushing, exit immediatly */
+  /* flushing, exit immediately */
   if (G_UNLIKELY (IS_FLUSHING (set)))
     goto flushing;
 
@@ -1417,12 +1420,10 @@ gst_poll_wait (GstPoll * set, GstClockTime timeout)
         restarting = TRUE;
     }
 
-    if (G_UNLIKELY (IS_FLUSHING (set))) {
-      /* we got woken up and we are flushing, we need to stop */
-      errno = EBUSY;
-      res = -1;
-      break;
-    }
+    /* we got woken up and we are flushing, we need to stop */
+    if (G_UNLIKELY (IS_FLUSHING (set)))
+      goto flushing;
+
   } while (G_UNLIKELY (restarting));
 
   DEC_WAITING (set);
@@ -1432,12 +1433,14 @@ gst_poll_wait (GstPoll * set, GstClockTime timeout)
   /* ERRORS */
 already_waiting:
   {
+    GST_LOG ("%p: we are already waiting", set);
     DEC_WAITING (set);
     errno = EPERM;
     return -1;
   }
 flushing:
   {
+    GST_LOG ("%p: we are flushing", set);
     DEC_WAITING (set);
     errno = EBUSY;
     return -1;
@@ -1445,6 +1448,7 @@ flushing:
 #ifdef G_OS_WIN32
 winsock_error:
   {
+    GST_LOG ("%p: winsock error", set);
     g_mutex_unlock (set->lock);
     DEC_WAITING (set);
     return -1;
@@ -1517,6 +1521,8 @@ gst_poll_set_flushing (GstPoll * set, gboolean flushing)
 {
   g_return_if_fail (set != NULL);
 
+  GST_LOG ("%p: flushing: %d", set, flushing);
+
   /* update the new state first */
   SET_FLUSHING (set, flushing);