Commit 87fce8ef authored by Max Kellermann's avatar Max Kellermann

mixer/alsa: use DeferredMonitor to update file descriptors

EventLoop::AddCall() and EventLoop::AddIdle() are unsafe, because we can't cancel those calls.
parent d2a4f64f
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
#include "event/DeferredMonitor.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "event/Call.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/ReusableArray.hxx" #include "util/ReusableArray.hxx"
#include "util/Clamp.hxx" #include "util/Clamp.hxx"
...@@ -40,29 +40,22 @@ ...@@ -40,29 +40,22 @@
#define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM" #define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM"
static constexpr unsigned VOLUME_MIXER_ALSA_INDEX_DEFAULT = 0; static constexpr unsigned VOLUME_MIXER_ALSA_INDEX_DEFAULT = 0;
class AlsaMixerMonitor final : private MultiSocketMonitor { class AlsaMixerMonitor final : MultiSocketMonitor, DeferredMonitor {
snd_mixer_t *mixer; snd_mixer_t *mixer;
ReusableArray<pollfd> pfd_buffer; ReusableArray<pollfd> pfd_buffer;
public: public:
AlsaMixerMonitor(EventLoop &_loop, snd_mixer_t *_mixer) AlsaMixerMonitor(EventLoop &_loop, snd_mixer_t *_mixer)
:MultiSocketMonitor(_loop), mixer(_mixer) { :MultiSocketMonitor(_loop), DeferredMonitor(_loop),
#ifdef USE_INTERNAL_EVENTLOOP mixer(_mixer) {
_loop.AddCall([this](){ InvalidateSockets(); }); DeferredMonitor::Schedule();
#else
_loop.AddIdle(InitAlsaMixerMonitor, this);
#endif
} }
private: private:
#ifndef USE_INTERNAL_EVENTLOOP virtual void RunDeferred() override {
static gboolean InitAlsaMixerMonitor(gpointer data) { InvalidateSockets();
AlsaMixerMonitor &amm = *(AlsaMixerMonitor *)data;
amm.InvalidateSockets();
return false;
} }
#endif
virtual int PrepareSockets() override; virtual int PrepareSockets() override;
virtual void DispatchSockets() override; virtual void DispatchSockets() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment