Commit 3dd55578 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

ThumbnailerWorker: Don't queue the same media twice

parent faeb4c19
......@@ -59,6 +59,9 @@ void ThumbnailerWorker::requestThumbnail( MediaPtr media, ThumbnailSizeType size
{
std::unique_lock<compat::Mutex> lock( m_mutex );
if ( m_queuedMedia.find( media->id() ) != cend( m_queuedMedia ) )
return;
Task t{
std::move( media ),
sizeType,
......@@ -66,7 +69,9 @@ void ThumbnailerWorker::requestThumbnail( MediaPtr media, ThumbnailSizeType size
desiredHeight,
position
};
m_queuedMedia.insert( t.media->id() );
m_tasks.push( std::move( t ) );
assert( m_tasks.size() == m_queuedMedia.size() );
if ( m_thread.get_id() == compat::Thread::id{} )
{
m_run = true;
......@@ -112,6 +117,8 @@ void ThumbnailerWorker::run()
}
t = std::move( m_tasks.front() );
m_tasks.pop();
m_queuedMedia.erase( t.media->id() );
assert( m_tasks.size() == m_queuedMedia.size() );
}
bool res = generateThumbnail( t );
m_ml->getCb()->onMediaThumbnailReady( t.media, t.sizeType, res );
......@@ -131,6 +138,7 @@ void ThumbnailerWorker::stop()
std::unique_lock<compat::Mutex> lock( m_mutex );
while ( m_tasks.empty() == false )
m_tasks.pop();
m_queuedMedia.clear();
}
m_cond.notify_all();
m_thread.join();
......
......@@ -30,6 +30,7 @@
#include <queue>
#include <atomic>
#include <set>
namespace medialibrary
{
......@@ -69,6 +70,7 @@ private:
compat::Mutex m_mutex;
compat::ConditionVariable m_cond;
std::queue<Task> m_tasks;
std::set<int64_t> m_queuedMedia;
std::atomic_bool m_run;
std::shared_ptr<IThumbnailer> m_generator;
compat::Thread m_thread;
......
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