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

MediaLibrary: Explicitely stop the discoverer worker

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