#endif
#include "gst_private.h"
+#include "glib-compat-private.h"
#include <sys/types.h>
#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))
#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
{
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;
gboolean result = TRUE;
if (g_atomic_int_dec_and_test (&set->control_pending)) {
+ GST_LOG ("%p: release", set);
result = RELEASE_EVENT (set);
}
return result;
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;
#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
}
/**
- * gst_poll_new_timer:
+ * gst_poll_new_timer: (skip)
*
* Create a new poll object that can be used for scheduling cancellable
* timeouts.
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;
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);
/* 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;
#ifdef G_OS_WIN32
winsock_error:
{
+ GST_LOG ("%p: winsock error", set);
g_mutex_unlock (set->lock);
DEC_WAITING (set);
return -1;
{
g_return_if_fail (set != NULL);
+ GST_LOG ("%p: flushing: %d", set, flushing);
+
/* update the new state first */
SET_FLUSHING (set, flushing);