output/httpd/Page: use std::shared_ptr instead of class RefCount

This commit is contained in:
Max Kellermann
2017-02-19 20:12:30 +01:00
parent 8b1931072a
commit 26e4a40cc7
8 changed files with 42 additions and 139 deletions

View File

@@ -90,9 +90,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
HttpdOutput::~HttpdOutput()
{
if (metadata != nullptr)
metadata->Unref();
delete prepared_encoder;
}
@@ -147,13 +144,11 @@ HttpdOutput::RunDeferred()
const std::lock_guard<Mutex> protect(mutex);
while (!pages.empty()) {
Page *page = pages.front();
PagePtr page = std::move(pages.front());
pages.pop();
for (auto &client : clients)
client.PushPage(page);
page->Unref();
}
/* wake up the client that may be waiting for the queue to be
@@ -204,7 +199,7 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
}
}
Page *
PagePtr
HttpdOutput::ReadPage()
{
if (unflushed_input >= 65536) {
@@ -235,7 +230,7 @@ HttpdOutput::ReadPage()
if (size == 0)
return nullptr;
return Page::Copy(buffer, size);
return std::make_shared<Page>(buffer, size);
}
inline void
@@ -282,8 +277,7 @@ HttpdOutput::Close()
clients.clear_and_dispose(DeleteDisposer());
});
if (header != nullptr)
header->Unref();
header.reset();
delete encoder;
}
@@ -326,13 +320,12 @@ HttpdOutput::Delay() const
}
void
HttpdOutput::BroadcastPage(Page *page)
HttpdOutput::BroadcastPage(PagePtr page)
{
assert(page != nullptr);
mutex.lock();
pages.push(page);
page->Ref();
pages.emplace(std::move(page));
mutex.unlock();
DeferredMonitor::Schedule();
@@ -346,7 +339,7 @@ HttpdOutput::BroadcastFromEncoder()
while (!pages.empty())
cond.wait(mutex);
Page *page;
PagePtr page;
while ((page = ReadPage()) != nullptr)
pages.push(page);
@@ -418,19 +411,14 @@ HttpdOutput::SendTag(const Tag &tag)
used as the new "header" page, which is sent to all
new clients */
Page *page = ReadPage();
auto page = ReadPage();
if (page != nullptr) {
if (header != nullptr)
header->Unref();
header = page;
header = std::move(page);
BroadcastPage(page);
}
} else {
/* use Icy-Metadata */
if (metadata != nullptr)
metadata->Unref();
static constexpr TagType types[] = {
TAG_ALBUM, TAG_ARTIST, TAG_TITLE,
TAG_NUM_OF_ITEM_TYPES
@@ -451,9 +439,8 @@ HttpdOutput::CancelAllClients()
const std::lock_guard<Mutex> protect(mutex);
while (!pages.empty()) {
Page *page = pages.front();
PagePtr page = std::move(pages.front());
pages.pop();
page->Unref();
}
for (auto &client : clients)