diff options
author | Max Kellermann <max@duempel.org> | 2013-12-31 16:31:36 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-04 18:22:55 +0100 |
commit | c9da3363a04bfdf8a0f0b2d974291e422a0345d2 (patch) | |
tree | fd79aa539d93da5c12d35f05a104a4c8e82258b9 /src/output/HttpdInternal.hxx | |
parent | 9bd4ed3e60df771241114ed460b8b5943ff57982 (diff) | |
download | mpd-c9da3363a04bfdf8a0f0b2d974291e422a0345d2.tar.gz mpd-c9da3363a04bfdf8a0f0b2d974291e422a0345d2.tar.xz mpd-c9da3363a04bfdf8a0f0b2d974291e422a0345d2.zip |
output/httpd: move all broadcast operations to the IOThread
Add a Page queue to class HttpdOutput, and use DeferredMonitor to
flush this queue inside the IOThread. This fixes a thread-safety
issue: much of EventLoop is not thread-safe, and the httpd plugin
ignored that problem.
Diffstat (limited to '')
-rw-r--r-- | src/output/HttpdInternal.hxx | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/output/HttpdInternal.hxx b/src/output/HttpdInternal.hxx index df9099335..f20d88b4e 100644 --- a/src/output/HttpdInternal.hxx +++ b/src/output/HttpdInternal.hxx @@ -29,6 +29,7 @@ #include "Timer.hxx" #include "thread/Mutex.hxx" #include "event/ServerSocket.hxx" +#include "event/DeferredMonitor.hxx" #ifdef _LIBCPP_VERSION /* can't use incomplete template arguments with libc++ */ @@ -36,6 +37,8 @@ #endif #include <forward_list> +#include <queue> +#include <list> struct config_param; class Error; @@ -46,7 +49,7 @@ class Page; struct Encoder; struct Tag; -class HttpdOutput final : ServerSocket { +class HttpdOutput final : ServerSocket, DeferredMonitor { struct audio_output base; /** @@ -80,6 +83,12 @@ public: */ mutable Mutex mutex; + /** + * This condition gets signalled when an item is removed from + * #pages. + */ + Cond cond; + private: /** * A #Timer object to synchronize this output with the @@ -97,6 +106,14 @@ private: */ Page *metadata; + /** + * The page queue, i.e. pages from the encoder to be + * broadcasted to all clients. This container is necessary to + * pass pages from the OutputThread to the IOThread. It is + * protected by #mutex, and removing signals #cond. + */ + std::queue<Page *, std::list<Page *>> pages; + public: /** * The configured name. @@ -248,6 +265,8 @@ public: void CancelAllClients(); private: + virtual void RunDeferred() override; + virtual void OnAccept(int fd, const sockaddr &address, size_t address_length, int uid) override; }; |