Commit 7d62c062 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Explicitely stop the discoverer worker

parent 30140738
...@@ -63,6 +63,8 @@ MediaLibrary::~MediaLibrary() ...@@ -63,6 +63,8 @@ MediaLibrary::~MediaLibrary()
// not be called anymore. // not be called anymore.
if ( m_vlcInstance.isValid() ) if ( m_vlcInstance.isValid() )
m_vlcInstance.logUnset(); m_vlcInstance.logUnset();
// Explicitely stop the discoverer, to avoid it writting while tearing down.
m_discoverer->stop();
File::clear(); File::clear();
Folder::clear(); Folder::clear();
Label::clear(); Label::clear();
......
...@@ -9,14 +9,7 @@ DiscovererWorker::DiscovererWorker() ...@@ -9,14 +9,7 @@ DiscovererWorker::DiscovererWorker()
DiscovererWorker::~DiscovererWorker() DiscovererWorker::~DiscovererWorker()
{ {
{ stop();
std::unique_lock<std::mutex> lock( m_mutex );
while ( m_entryPoints.empty() == false )
m_entryPoints.pop();
m_run = false;
}
m_cond.notify_all();
m_thread.join();
} }
void DiscovererWorker::addDiscoverer( std::unique_ptr<IDiscoverer> discoverer ) void DiscovererWorker::addDiscoverer( std::unique_ptr<IDiscoverer> discoverer )
...@@ -29,6 +22,21 @@ void DiscovererWorker::setCallback(IMediaLibraryCb* cb) ...@@ -29,6 +22,21 @@ void DiscovererWorker::setCallback(IMediaLibraryCb* cb)
m_cb = cb; m_cb = cb;
} }
void DiscovererWorker::stop()
{
bool running = true;
if ( m_run.compare_exchange_strong( running, false ) )
{
{
std::unique_lock<std::mutex> lock( m_mutex );
while ( m_entryPoints.empty() == false )
m_entryPoints.pop();
}
m_cond.notify_all();
m_thread.join();
}
}
bool DiscovererWorker::discover( const std::string& entryPoint ) bool DiscovererWorker::discover( const std::string& entryPoint )
{ {
if ( entryPoint.length() == 0 ) if ( entryPoint.length() == 0 )
......
...@@ -18,6 +18,7 @@ public: ...@@ -18,6 +18,7 @@ public:
virtual ~DiscovererWorker(); virtual ~DiscovererWorker();
void addDiscoverer( std::unique_ptr<IDiscoverer> discoverer ); void addDiscoverer( std::unique_ptr<IDiscoverer> discoverer );
void setCallback( IMediaLibraryCb* cb ); void setCallback( IMediaLibraryCb* cb );
void stop();
virtual bool discover( const std::string& entryPoint ) override; virtual bool discover( const std::string& entryPoint ) override;
virtual void reload() override; virtual void reload() override;
......
Supports Markdown
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