glib threadpools experimental in thumb updater

This commit is contained in:
Andrey Skvortsov
2010-09-14 00:05:56 -07:00
parent 71b2f5b33e
commit 58c887a445
3 changed files with 60 additions and 25 deletions

View File

@@ -25,14 +25,15 @@ ThumbImageUpdater thumbImageUpdater;
ThumbImageUpdater::ThumbImageUpdater ()
: tostop(false), stopped(true), qMutex(NULL), startMutex(NULL) {
threadPool = new Glib::Thread* [threadNum];
//threadPool = new Glib::Thread* [threadNum];
threadPool = 0;;
}
ThumbImageUpdater::~ThumbImageUpdater ()
{
delete threadPool;
}
//ThumbImageUpdater::~ThumbImageUpdater ()
//{
// delete threadPool;
//}
void ThumbImageUpdater::add (Thumbnail* t, const rtengine::procparams::ProcParams& params, int height, bool* priority, ThumbImageUpdateListener* l) {
@@ -69,7 +70,15 @@ void ThumbImageUpdater::process () {
if (stopped) {
#undef THREAD_PRIORITY_LOW
stopped = false;
// if (thread)
// thread->join();
if(!threadPool)
threadPool = new Glib::ThreadPool(4,0);
thread = Glib::Thread::create(sigc::mem_fun(*this, &ThumbImageUpdater::process_), (unsigned long int)0, true, true, Glib::THREAD_PRIORITY_LOW);
//qMutex->lock ();
// threadPool->push(sigc::mem_fun(*this, &ThumbImageUpdater::process_));
//qMutex->unlock ();
}
}
@@ -78,34 +87,50 @@ void ThumbImageUpdater::process_ () {
stopped = false;
tostop = false;
// GError *err;
while (!tostop && !jqueue.empty ()) {
qMutex->lock ();
int threads = 0;
for (; threads<threadNum && !jqueue.empty (); threads++) {
//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;
for (i=jqueue.begin (); i!=jqueue.end(); i++)
if (*(i->priority))
break;
if (i==jqueue.end())
i = jqueue.begin();
Job current = *i;
Job current = *i;
if (current.listener)
threadPool->push(sigc::bind(sigc::mem_fun(*this, &ThumbImageUpdater::processJob), current));
// if(! threadPool)
// threadPool = g_thread_pool_new((void*)&ThumbImageUpdater::processJob, (gpointer)&current, 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);
if (current.listener)
threadPool[threads] = Glib::Thread::create(sigc::bind(sigc::mem_fun(*this, &ThumbImageUpdater::processJob), current), 0, true, true, Glib::THREAD_PRIORITY_LOW);
//else
// threadPool[threads] = NULL;
}
// }
qMutex->unlock ();
for (int j=0; j<threads; j++)
if (threadPool[j])
threadPool[j]->join ();
// for (int j=0; j<threads; j++)
// if (threadPool[j])
// threadPool[j]-> join ();
for(int j =0; j <threadNum;j++)
threadPool[j] = NULL;
//for(int j =0; j <threadNum;j++)
// threadPool[j] = NULL;
}
stopped = true;
}
@@ -128,10 +153,12 @@ void ThumbImageUpdater::stop () {
return; }
gdk_threads_leave();
tostop = true;
Glib::Thread::self()->yield();
if (!stopped)
thread->join ();
tostop = true;
Glib::Thread::self()->yield();
if (!stopped)
threadPool->shutdown(TRUE);
thread->join ();
gdk_threads_enter();
}