Cancel linux poll

I am moving the audio mixer from directsound on Windows to alsa on Linux. I am polling, say, 16 file descriptors using the polling system call. Now I need to somehow cancel the survey. On Windows, I use WaitForMultipleObjects using events, and when I need to cancel the wait, I just SetEvent on one of the events that cause the wait to return. Is there a way to mark the file descriptor in Linux “ready” so the poll returns?

I looked at ppoll, but I am not familiar with the signals, and I do not want to handle unnecessary race conditions. I mean, if alsa can set the file descriptors to "ready", I should also be able to;)

+3
source share
2 answers

If you create a channel using a function pipe(), you can add the output end to the list poll(). Then you can write something at the inlet end of the pipe and your poll will return. Like your version of Windows.

You will need to use something asynchronous, such as threads or signal handlers, to make this work.

Another option is to use sigaction()a signal handler without a flag to install it SA_RESTART. You can use an unused type signal SIGUSR1or one of the real-time signals. If you want to abort poll(), then you send this signal, but poll()will return with -1 and errno will tune to EINTR.

, poll(), sigmask() .

+3

.

while (not exit_condition):
    int poll(struct pollfd *fds, nfds_t nfds, int timeout);
0

Source: https://habr.com/ru/post/1772042/


All Articles