mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 23:00:41 +00:00
osdep/io: introduce mp_flush_wakeup_pipe()
Makes a fairly common occurence with wakeup_pipes easier to handle.
This commit is contained in:
parent
f3f4e048d8
commit
c3e11f7b7c
@ -497,10 +497,8 @@ int ao_wait_poll(struct ao *ao, struct pollfd *fds, int num_fds,
|
||||
bool wakeup = false;
|
||||
if (p_fds[num_fds].revents & POLLIN) {
|
||||
wakeup = true;
|
||||
// flush the wakeup pipe contents - might "drown" some wakeups, but
|
||||
// that's ok for our use-case
|
||||
char buf[100];
|
||||
(void)read(p->wakeup_pipe[0], buf, sizeof(buf));
|
||||
// might "drown" some wakeups, but that's ok for our use-case
|
||||
mp_flush_wakeup_pipe(p->wakeup_pipe[0]);
|
||||
}
|
||||
return (r >= 0 || r == -EINTR) ? wakeup : -1;
|
||||
}
|
||||
|
@ -133,8 +133,7 @@ static void *client_thread(void *p)
|
||||
}
|
||||
|
||||
if (fds[0].revents & POLLIN) {
|
||||
char discard[100];
|
||||
(void)read(pipe_fd, discard, sizeof(discard));
|
||||
mp_flush_wakeup_pipe(pipe_fd);
|
||||
|
||||
while (1) {
|
||||
mpv_event *event = mpv_wait_event(arg->client, 0);
|
||||
|
@ -85,6 +85,14 @@ int mp_make_wakeup_pipe(int pipes[2])
|
||||
}
|
||||
#endif
|
||||
|
||||
void mp_flush_wakeup_pipe(int pipe_end)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
char buf[100];
|
||||
(void)read(pipe_end, buf, sizeof(buf));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -47,6 +47,7 @@
|
||||
bool mp_set_cloexec(int fd);
|
||||
int mp_make_cloexec_pipe(int pipes[2]);
|
||||
int mp_make_wakeup_pipe(int pipes[2]);
|
||||
void mp_flush_wakeup_pipe(int pipe_end);
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <wchar.h>
|
||||
|
@ -1934,10 +1934,8 @@ void vo_x11_wait_events(struct vo *vo, int64_t until_time_us)
|
||||
|
||||
poll(fds, 2, timeout_ms);
|
||||
|
||||
if (fds[1].revents & POLLIN) {
|
||||
char buf[100];
|
||||
(void)read(x11->wakeup_pipe[0], buf, sizeof(buf)); // flush
|
||||
}
|
||||
if (fds[1].revents & POLLIN)
|
||||
mp_flush_wakeup_pipe(x11->wakeup_pipe[0]);
|
||||
}
|
||||
|
||||
static void xscreensaver_heartbeat(struct vo_x11_state *x11)
|
||||
|
Loading…
Reference in New Issue
Block a user