glib threadpools experimental in thumb updater
This commit is contained in:
@@ -8973,6 +8973,13 @@ dcrMutex->lock ();
|
|||||||
image = (UshORt (*)[4])calloc (height*width*sizeof *image + meta_length, 1);
|
image = (UshORt (*)[4])calloc (height*width*sizeof *image + meta_length, 1);
|
||||||
meta_data = (char *) (image + height*width);
|
meta_data = (char *) (image + height*width);
|
||||||
|
|
||||||
|
if(!image)
|
||||||
|
{
|
||||||
|
fclose(ifp);
|
||||||
|
dcrMutex->unlock ();
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
if (setjmp (failure)) {
|
if (setjmp (failure)) {
|
||||||
if (image)
|
if (image)
|
||||||
free (image);
|
free (image);
|
||||||
|
@@ -25,14 +25,15 @@ ThumbImageUpdater thumbImageUpdater;
|
|||||||
ThumbImageUpdater::ThumbImageUpdater ()
|
ThumbImageUpdater::ThumbImageUpdater ()
|
||||||
: tostop(false), stopped(true), qMutex(NULL), startMutex(NULL) {
|
: tostop(false), stopped(true), qMutex(NULL), startMutex(NULL) {
|
||||||
|
|
||||||
threadPool = new Glib::Thread* [threadNum];
|
//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) {
|
||||||
|
|
||||||
@@ -69,7 +70,15 @@ void ThumbImageUpdater::process () {
|
|||||||
if (stopped) {
|
if (stopped) {
|
||||||
#undef THREAD_PRIORITY_LOW
|
#undef THREAD_PRIORITY_LOW
|
||||||
stopped = false;
|
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);
|
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;
|
stopped = false;
|
||||||
tostop = false;
|
tostop = false;
|
||||||
|
|
||||||
|
// GError *err;
|
||||||
while (!tostop && !jqueue.empty ()) {
|
while (!tostop && !jqueue.empty ()) {
|
||||||
|
|
||||||
qMutex->lock ();
|
qMutex->lock ();
|
||||||
int threads = 0;
|
//int threads = 0;
|
||||||
for (; threads<threadNum && !jqueue.empty (); threads++) {
|
//for (; threads<threadNum && !jqueue.empty (); threads++) {
|
||||||
// find first entry having update priority, if any
|
// 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();
|
||||||
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)¤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);
|
||||||
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
|
//else
|
||||||
// threadPool[threads] = NULL;
|
// threadPool[threads] = NULL;
|
||||||
}
|
// }
|
||||||
qMutex->unlock ();
|
qMutex->unlock ();
|
||||||
|
|
||||||
for (int j=0; j<threads; j++)
|
// for (int j=0; j<threads; j++)
|
||||||
if (threadPool[j])
|
// if (threadPool[j])
|
||||||
threadPool[j]->join ();
|
// threadPool[j]-> join ();
|
||||||
|
|
||||||
for(int j =0; j <threadNum;j++)
|
//for(int j =0; j <threadNum;j++)
|
||||||
threadPool[j] = NULL;
|
// threadPool[j] = NULL;
|
||||||
}
|
}
|
||||||
stopped = true;
|
stopped = true;
|
||||||
}
|
}
|
||||||
@@ -128,10 +153,12 @@ void ThumbImageUpdater::stop () {
|
|||||||
return; }
|
return; }
|
||||||
|
|
||||||
gdk_threads_leave();
|
gdk_threads_leave();
|
||||||
tostop = true;
|
tostop = true;
|
||||||
Glib::Thread::self()->yield();
|
|
||||||
if (!stopped)
|
Glib::Thread::self()->yield();
|
||||||
thread->join ();
|
if (!stopped)
|
||||||
|
threadPool->shutdown(TRUE);
|
||||||
|
thread->join ();
|
||||||
gdk_threads_enter();
|
gdk_threads_enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <rtengine.h>
|
#include <rtengine.h>
|
||||||
#include <thumbnail.h>
|
#include <thumbnail.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
class ThumbImageUpdateListener {
|
class ThumbImageUpdateListener {
|
||||||
|
|
||||||
@@ -46,11 +47,11 @@ class ThumbImageUpdater {
|
|||||||
Glib::Thread* thread;
|
Glib::Thread* thread;
|
||||||
Glib::Mutex* qMutex;
|
Glib::Mutex* qMutex;
|
||||||
Glib::Mutex* startMutex;
|
Glib::Mutex* startMutex;
|
||||||
Glib::Thread **threadPool;
|
//Glib::Thread **threadPool;
|
||||||
|
Glib::ThreadPool * threadPool;
|
||||||
|
|
||||||
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