From 0f55cf13b405dda0f30b151255daee5e52b667e1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 26 Jan 2009 12:52:12 +0100 Subject: [PATCH] Avoid unneeded reads from the control socket Add a new variable that keeps track of the status of the control socket. This allows us to avoid doing a read() on the control socket when we did not write anything to it. Fixes #568438. --- gst/gstpoll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gst/gstpoll.c b/gst/gstpoll.c index a5a540e3cb..6e77c2bfbf 100644 --- a/gst/gstpoll.c +++ b/gst/gstpoll.c @@ -96,6 +96,7 @@ G_STMT_START { \ unsigned char c = command; \ ssize_t res; \ res = write (set->control_write_fd.fd, &c, 1); \ + set->control_pending = TRUE; \ } G_STMT_END #define READ_COMMAND(set, command, res) \ @@ -140,7 +141,6 @@ struct _GstPoll GstPollFD control_write_fd; #else GArray *active_fds_ignored; - GArray *events; GArray *active_events; @@ -151,6 +151,7 @@ struct _GstPoll gboolean new_controllable; gboolean waiting; gboolean flushing; + gboolean control_pending; }; static gint @@ -465,6 +466,7 @@ gst_poll_new (gboolean controllable) nset = g_slice_new0 (GstPoll); nset->lock = g_mutex_new (); + nset->control_pending = FALSE; #ifndef G_OS_WIN32 nset->mode = GST_POLL_MODE_AUTO; nset->fds = g_array_new (FALSE, FALSE, sizeof (struct pollfd)); @@ -982,7 +984,7 @@ gst_poll_check_ctrl_commands (GstPoll * set, gint res, gboolean * restarting) /* check if the poll/select was aborted due to a command */ if (set->controllable) { #ifndef G_OS_WIN32 - while (TRUE) { + while (TRUE && set->control_pending) { guchar cmd; gint result; @@ -993,6 +995,7 @@ gst_poll_check_ctrl_commands (GstPoll * set, gint res, gboolean * restarting) READ_COMMAND (set, cmd, result); if (result <= 0) { /* no more commands, quit the loop */ + set->control_pending = FALSE; break; }