문제

I am porting an audio mixer from directsound on Windows to alsa on Linux. I am polling on, let's say, 16 file descriptors using the system call "poll". Now i need to be able to abort the polling somehow. On Windows i am using the WaitForMultipleObjects using events and when i need to abort the waiting i just SetEvent on one of the events causing the wait to return. Is there any way to mark a file descriptor in Linux "ready" so that the poll will return?

I have taken a look at ppoll but i am not familiar with signals and i don't want to handle unnecessary race conditions. I mean, if alsa can set the file descriptors to "ready" i should also be able to ;)

도움이 되었습니까?

해결책

If you make a pipe using the pipe() function, you can add the output end into your poll() list. Then you can write something into the input end of the pipe and your poll will return. Much like your Windows version.

You'd need to be using something asynchronous like threads or signal handlers to make that work.

Another option would be to use sigaction() to set a signal handler without the SA_RESTART flag. You could use an unused signal like SIGUSR1 or one of the real-time signals. When you want to interrupt the poll() then you send that signal and poll() will return with -1 and errno set to EINTR.

It would be possible for a different signal to interrupt your poll() as well, unless you used sigmask() to block unwanted signals.

다른 팁

Use the timeout and check the exit condition.

while (not exit_condition):
    int poll(struct pollfd *fds, nfds_t nfds, int timeout);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top