lib/upnp/Discovery: protect "downloaders" accesses with mutex

This commit is contained in:
Max Kellermann 2018-01-02 14:55:57 +01:00
parent 0a4b866d8a
commit 3f4f7b0a53
2 changed files with 9 additions and 0 deletions

View File

@ -42,12 +42,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))),
request(*parent.curl, url.c_str(), *this)
{
const std::lock_guard<Mutex> protect(parent.mutex);
parent.downloaders.push_back(*this);
}
void
UPnPDeviceDirectory::Downloader::Destroy() noexcept
{
const std::lock_guard<Mutex> protect(parent.mutex);
parent.downloaders.erase_and_dispose(parent.downloaders.iterator_to(*this),
DeleteDisposer());
}
@ -265,6 +267,7 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop,
UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept
{
BlockingCall(GetEventLoop(), [this](){
const std::lock_guard<Mutex> protect(mutex);
downloaders.clear_and_dispose(DeleteDisposer());
});
}

View File

@ -137,9 +137,15 @@ class UPnPDeviceDirectory final : UpnpCallback {
Mutex mutex;
/**
* Protected by #mutex.
*/
boost::intrusive::list<Downloader,
boost::intrusive::constant_time_size<false>> downloaders;
/**
* Protected by #mutex.
*/
std::list<ContentDirectoryDescriptor> directories;
/**