vlc_spin_lock (&internals->spin);
signaled = internals->b_signaled;
- if ((!signaled) && (internals->pipes[0] == -1))
+ if (internals->pipes[0] == -1)
{
internals->pipes[0] = pfd[0];
internals->pipes[1] = pfd[1];
}
+ else
+ race = VLC_TRUE;
}
vlc_spin_unlock (&internals->spin);
- if (race || signaled)
- {
+ if (race)
+ { /* Race condition: two threads call pipe() - unlikely */
close (pfd[0]);
close (pfd[1]);
-
- if (signaled)
- { /* vlc_object_signal() was already invoked! */
- errno = EINTR;
- return -1;
- }
}
+ if (signaled)
+ /* Race condition: lc_object_signal() already invoked! */
+ while (write (internals->pipes[1], &(char){ 0 }, 1) < 0);
+
return internals->pipes[0];
}
*****************************************************************************
* Reads from a network socket.
* If waitall is true, then we repeat until we have read the right amount of
- * data; in that case, a short count means EOF has been reached.
+ * data; in that case, a short count means EOF has been reached or the VLC
+ * object has been signaled.
*****************************************************************************/
ssize_t
__net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
{ .fd = -1, .events = POLLIN },
};
- vlc_object_lock (p_this);
- ufd[1].fd = vlc_object_waitpipe (p_this);
-
while (i_buflen > 0)
{
int val;
- if (!vlc_object_alive (p_this))
+ ufd[1].fd = vlc_object_waitpipe (p_this);
+ if (ufd[1].fd == -1)
{
-#if defined(WIN32) || defined(UNDER_CE)
- WSASetLastError (WSAEINTR);
-#else
- errno = EINTR;
-#endif
- goto error;
}
ufd[0].revents = ufd[1].revents = 0;
- vlc_object_unlock (p_this);
val = poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1);
- vlc_object_lock (p_this);
if (val < 0)
goto error;
if (ufd[1].revents)
{
msg_Dbg (p_this, "socket %d polling interrupted", fd);
- vlc_object_wait (p_this);
- msg_Dbg (p_this, "socket %d polling restarting", fd);
- continue;
+ if (i_total == 0)
+ {
+#if defined(WIN32) || defined(UNDER_CE)
+ WSASetLastError (WSAEINTR);
+#else
+ errno = EINTR;
+#endif
+ goto error;
+ }
+ break;
}
assert (ufd[0].revents);
break;
}
- vlc_object_unlock (p_this);
return i_total;
error:
msg_Err (p_this, "Read error: %m");
-
- vlc_object_unlock (p_this);
return -1;
}
assert( pi_fd != NULL );
- vlc_object_lock (p_this);
evfd = vlc_object_waitpipe (p_this);
- while (vlc_object_alive (p_this))
+ for (;;)
{
unsigned n = 0;
while (pi_fd[n] != -1)
ufd[i].events = POLLIN;
ufd[i].revents = 0;
}
+ if (evfd == -1)
+ n--; /* avoid EBADF */
- vlc_object_unlock (p_this);
switch (poll (ufd, n, timeout))
{
case -1:
case 0:
return -1; /* NOTE: p_this already unlocked */
}
- vlc_object_lock (p_this);
if (ufd[n].revents)
{
- vlc_object_wait (p_this);
errno = EINTR;
break;
}
*/
memmove (pi_fd + i, pi_fd + i + 1, n - (i + 1));
pi_fd[n - 1] = sfd;
- vlc_object_unlock (p_this);
return fd;
}
}
- vlc_object_unlock (p_this);
return -1;
}