Refactor thumbimageupdater threading schema. Use glib threadpool class, 8 threads, remove container thread and fix stop code. This should fix some crashes caused by thread conflicts occurred if folders switched quickly multiple times.
This commit is contained in:
@@ -19,21 +19,18 @@
|
|||||||
#include <thumbimageupdater.h>
|
#include <thumbimageupdater.h>
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
|
||||||
#define threadNum 4 // IF LCMS GETS THREAD SAFETY WE CAN ENABLE MORE THREADS
|
#define threadNum 8
|
||||||
ThumbImageUpdater thumbImageUpdater;
|
ThumbImageUpdater thumbImageUpdater;
|
||||||
|
|
||||||
ThumbImageUpdater::ThumbImageUpdater ()
|
ThumbImageUpdater::ThumbImageUpdater ()
|
||||||
: tostop(false), stopped(true), qMutex(NULL), startMutex(NULL) {
|
: tostop(false), stopped(true), qMutex(NULL), startMutex(NULL), threadPool(NULL) {
|
||||||
|
|
||||||
//threadPool = new Glib::Thread* [threadNum];
|
|
||||||
threadPool = 0;;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//ThumbImageUpdater::~ThumbImageUpdater ()
|
ThumbImageUpdater::~ThumbImageUpdater ()
|
||||||
//{
|
{
|
||||||
// delete threadPool;
|
delete threadPool;
|
||||||
//}
|
}
|
||||||
|
|
||||||
void ThumbImageUpdater::add (Thumbnail* t, const rtengine::procparams::ProcParams& params, int height, bool* priority, ThumbImageUpdateListener* l) {
|
void ThumbImageUpdater::add (Thumbnail* t, const rtengine::procparams::ProcParams& params, int height, bool* priority, ThumbImageUpdateListener* l) {
|
||||||
|
|
||||||
@@ -68,17 +65,13 @@ void ThumbImageUpdater::add (Thumbnail* t, const rtengine::procparams::ProcParam
|
|||||||
void ThumbImageUpdater::process () {
|
void ThumbImageUpdater::process () {
|
||||||
|
|
||||||
if (stopped) {
|
if (stopped) {
|
||||||
#undef THREAD_PRIORITY_LOW
|
|
||||||
stopped = false;
|
stopped = false;
|
||||||
// if (thread)
|
|
||||||
// thread->join();
|
|
||||||
|
|
||||||
if(!threadPool)
|
if(!threadPool)
|
||||||
threadPool = new Glib::ThreadPool(4,0);
|
threadPool = new Glib::ThreadPool(threadNum,0);
|
||||||
thread = Glib::Thread::create(sigc::mem_fun(*this, &ThumbImageUpdater::process_), (unsigned long int)0, true, true, Glib::THREAD_PRIORITY_LOW);
|
|
||||||
//qMutex->lock ();
|
//thread = Glib::Thread::create (sigc::mem_fun(*this, &ThumbImageUpdater::process_), (unsigned long int)0, true, true, Glib::THREAD_PRIORITY_NORMAL);
|
||||||
// threadPool->push(sigc::mem_fun(*this, &ThumbImageUpdater::process_));
|
process_();
|
||||||
//qMutex->unlock ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,23 +80,13 @@ void ThumbImageUpdater::process_ () {
|
|||||||
stopped = false;
|
stopped = false;
|
||||||
tostop = false;
|
tostop = false;
|
||||||
|
|
||||||
// GError *err;
|
|
||||||
while (!tostop && !jqueue.empty ()) {
|
while (!tostop && !jqueue.empty ()) {
|
||||||
|
|
||||||
qMutex->lock ();
|
|
||||||
//int threads = 0;
|
|
||||||
//for (; threads<threadNum && !jqueue.empty (); threads++) {
|
|
||||||
// find first entry having update priority, if any
|
|
||||||
|
|
||||||
|
|
||||||
// while(!jqueue.empty())
|
|
||||||
// {
|
|
||||||
std::list<Job>::iterator i;
|
std::list<Job>::iterator i;
|
||||||
for (i=jqueue.begin (); i!=jqueue.end(); i++)
|
for (i=jqueue.begin (); i!=jqueue.end(); i++)
|
||||||
if (*(i->priority))
|
if (*(i->priority))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
if (i==jqueue.end())
|
if (i==jqueue.end())
|
||||||
i = jqueue.begin();
|
i = jqueue.begin();
|
||||||
|
|
||||||
@@ -111,28 +94,12 @@ void ThumbImageUpdater::process_ () {
|
|||||||
if (current.listener)
|
if (current.listener)
|
||||||
threadPool->push(sigc::bind(sigc::mem_fun(*this, &ThumbImageUpdater::processJob), current));
|
threadPool->push(sigc::bind(sigc::mem_fun(*this, &ThumbImageUpdater::processJob), current));
|
||||||
|
|
||||||
// if(! threadPool)
|
|
||||||
// threadPool = g_thread_pool_new((void*)&ThumbImageUpdater::processJob, (gpointer)¤t, 4, FALSE, &err);
|
|
||||||
// else
|
|
||||||
// g_thread_pool_push(threadPool, (gpointer)current, &err);
|
|
||||||
|
|
||||||
//threadPool[threads] =
|
|
||||||
// Glib::Thread::create (sigc::bind(sigc::mem_fun(*this, &ThumbImageUpdater::processJob), current), 0, false, true, Glib::THREAD_PRIORITY_LOW);
|
|
||||||
|
|
||||||
jqueue.erase (i);
|
jqueue.erase (i);
|
||||||
//else
|
|
||||||
// threadPool[threads] = NULL;
|
|
||||||
// }
|
|
||||||
qMutex->unlock ();
|
|
||||||
|
|
||||||
// for (int j=0; j<threads; j++)
|
|
||||||
// if (threadPool[j])
|
|
||||||
// threadPool[j]-> join ();
|
|
||||||
|
|
||||||
//for(int j =0; j <threadNum;j++)
|
|
||||||
// threadPool[j] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stopped = true;
|
stopped = true;
|
||||||
|
//printf("Threads # %d \n", threadPool->get_num_threads());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThumbImageUpdater::processJob (Job current) {
|
void ThumbImageUpdater::processJob (Job current) {
|
||||||
@@ -148,17 +115,13 @@ void ThumbImageUpdater::processJob (Job current) {
|
|||||||
|
|
||||||
void ThumbImageUpdater::stop () {
|
void ThumbImageUpdater::stop () {
|
||||||
|
|
||||||
if (stopped) {
|
|
||||||
tostop = true;
|
|
||||||
return; }
|
|
||||||
|
|
||||||
gdk_threads_leave();
|
gdk_threads_leave();
|
||||||
tostop = true;
|
tostop = true;
|
||||||
|
|
||||||
Glib::Thread::self()->yield();
|
if (threadPool) {
|
||||||
if (!stopped)
|
|
||||||
threadPool->shutdown(TRUE);
|
threadPool->shutdown(TRUE);
|
||||||
thread->join ();
|
threadPool = NULL;
|
||||||
|
}
|
||||||
gdk_threads_enter();
|
gdk_threads_enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,6 +52,7 @@ class ThumbImageUpdater {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ThumbImageUpdater ();
|
ThumbImageUpdater ();
|
||||||
|
~ThumbImageUpdater ();
|
||||||
|
|
||||||
void add (Thumbnail* t, const rtengine::procparams::ProcParams& params, int height, bool* priority, ThumbImageUpdateListener* l);
|
void add (Thumbnail* t, const rtengine::procparams::ProcParams& params, int height, bool* priority, ThumbImageUpdateListener* l);
|
||||||
void process ();
|
void process ();
|
||||||
|
Reference in New Issue
Block a user