Commit 782a6148 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Parser: Lazily start parser threads

parent 1f18aaeb
......@@ -68,8 +68,6 @@ void Parser::parse( std::shared_ptr<Media> media, std::shared_ptr<File> file )
void Parser::start()
{
restore();
for ( auto& s : m_services )
s->start();
}
void Parser::pause()
......
......@@ -87,9 +87,18 @@ void ParserService::stop()
void ParserService::parse( std::unique_ptr<parser::Task> t )
{
std::lock_guard<compat::Mutex> lock( m_lock );
m_tasks.push( std::move( t ) );
m_cond.notify_all();
if ( m_threads.size() == 0 )
{
// Since the thread isn't started, no need to lock the mutex before pushing the task
m_tasks.push( std::move( t ) );
start();
}
else
{
std::lock_guard<compat::Mutex> lock( m_lock );
m_tasks.push( std::move( t ) );
m_cond.notify_all();
}
}
void ParserService::initialize( MediaLibrary* ml, IParserCb* parserCb )
......
......@@ -45,7 +45,6 @@ public:
ParserService();
virtual ~ParserService() = default;
void start();
void pause();
void resume();
///
......@@ -75,6 +74,7 @@ protected:
private:
// Thread(s) entry point
void start();
void mainloop();
void setIdle( bool isIdle );
......
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