X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=alsa_pool.cpp;h=bcda16315329e87b039a5240a015e7b050c4d5d3;hb=refs%2Fheads%2Fmultichannel_audio;hp=5983446e37ab4f687cfaa7a9e4db11d497eff711;hpb=9932a195e442b67ba95bb1377f29aac27f68eb0e;p=nageru diff --git a/alsa_pool.cpp b/alsa_pool.cpp index 5983446..bcda163 100644 --- a/alsa_pool.cpp +++ b/alsa_pool.cpp @@ -1,15 +1,21 @@ #include "alsa_pool.h" -#include -#include -#include +#include #include +#include #include +#include +#include #include +#include #include #include #include +#include +#include +#include #include +#include #include "alsa_input.h" #include "audio_mixer.h" @@ -20,6 +26,12 @@ using namespace std; using namespace std::placeholders; +ALSAPool::ALSAPool() +{ + should_quit_fd = eventfd(/*initval=*/0, /*flags=*/0); + assert(should_quit_fd != -1); +} + ALSAPool::~ALSAPool() { for (Device &device : devices) { @@ -28,6 +40,11 @@ ALSAPool::~ALSAPool() } } should_quit = true; + const uint64_t one = 1; + if (write(should_quit_fd, &one, sizeof(one)) != sizeof(one)) { + perror("write(should_quit_fd)"); + exit(1); + } inotify_thread.join(); while (retry_threads_running > 0) { @@ -289,12 +306,15 @@ void ALSAPool::inotify_thread_func() int size = sizeof(inotify_event) + NAME_MAX + 1; unique_ptr buf(new char[size]); while (!should_quit) { - pollfd fds; - fds.fd = inotify_fd; - fds.events = POLLIN; - fds.revents = 0; - - int ret = poll(&fds, 1, 100); + pollfd fds[2]; + fds[0].fd = inotify_fd; + fds[0].events = POLLIN; + fds[0].revents = 0; + fds[1].fd = should_quit_fd; + fds[1].events = POLLIN; + fds[1].revents = 0; + + int ret = poll(fds, 2, -1); if (ret == -1) { if (errno == EINTR) { continue; @@ -307,6 +327,8 @@ void ALSAPool::inotify_thread_func() continue; } + if (fds[1].revents) break; // should_quit_fd asserted. + ret = read(inotify_fd, buf.get(), size); if (ret == -1) { if (errno == EINTR) { @@ -350,6 +372,7 @@ void ALSAPool::inotify_thread_func() } close(watch_fd); close(inotify_fd); + close(should_quit_fd); } void ALSAPool::reset_device(unsigned index)